Loading include/arch/msp430fr5994lp/driver/adc.h +3 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ #ifndef ADC_H #define ADC_H #include <stdint.h> class ADC { private: ADC(ADC const ©); Loading @@ -15,6 +17,7 @@ class ADC { float getTemp(); float getVCC(); uint16_t getReading(); }; extern ADC adc; Loading src/arch/msp430fr5994lp/driver/adc.cc +33 −7 Original line number Diff line number Diff line Loading @@ -17,14 +17,13 @@ float ADC::getTemp() REFCTL0 = REFVSEL_0 | REFON; ADC12CTL0 &= ~ADC12ENC; ADC12CTL0 = ADC12SHT0_8 | ADC12ON; ADC12CTL0 = ADC12SHT0_8 | ADC12ON; // Sample and Hold: 256 ADC12CLK Cycles ADC12CTL1 = ADC12SHP; ADC12CTL3 = ADC12TCMAP; ADC12MCTL0 = ADC12VRSEL_1 | ADC12INCH_30; while(!(REFCTL0 & REFGENRDY)); ADC12CTL0 |= ADC12ENC; ADC12CTL0 |= ADC12SC; ADC12CTL0 |= ADC12ENC | ADC12SC; while (ADC12CTL1 & ADC12BUSY); ret = (float)((long)ADC12MEM0 - CALADC12_12V_30C) * (85 - 30) / Loading @@ -49,18 +48,16 @@ float ADC::getVCC() REFCTL0 = REFVSEL_1 | REFON; ADC12CTL0 &= ~ADC12ENC; ADC12CTL0 = ADC12SHT0_8 | ADC12ON; ADC12CTL0 = ADC12SHT0_8 | ADC12ON; // Sample and Hold: 256 ADC12CLK Cycles ADC12CTL1 = ADC12SHP; ADC12CTL3 = ADC12BATMAP; ADC12MCTL0 = ADC12VRSEL_1 | ADC12INCH_31; while(!(REFCTL0 & REFGENRDY)); ADC12CTL0 |= ADC12ENC; ADC12CTL0 |= ADC12SC; ADC12CTL0 |= ADC12ENC | ADC12SC; while (ADC12CTL1 & ADC12BUSY); ret = (float)ADC12MEM0 / 4096 * 2 * 2; return ret; // Disable ADC ADC12CTL0 &= ~ADC12ENC; // disable any conversion to allow ADC configuration Loading @@ -73,4 +70,33 @@ float ADC::getVCC() return ret; } uint16_t ADC::getReading() { ADC12CTL0 &= ~ADC12ENC; // disable ADC for configuration ADC12CTL0 = ADC12SHT0_8 | ADC12SHT1_8 | ADC12ON; // Sample & Hold: 64 ADC12CLK cycles; enable ADC ADC12CTL1 = ADC12SHP; // MODOSC, no prescaler ADC12CTL2 = ADC12RES_2; // 12 bit resolution ADC12CTL3 = ADC12CSTARTADD_0; // store reading in ADCMEM0 // disable output driver and input schmitt triggers on P3.0 (A12) P3SEL0 |= BIT0; P3SEL1 |= BIT0; // use default reference (AVSS / AVCC) (only required if changed by some other runtime code beforehand) // read from A12 (P3.0) ADC12MCTL0 = ADC12INCH_12; // get reading ADC12CTL0 |= ADC12ENC | ADC12SC; while (ADC12CTL1 & ADC12BUSY); uint16_t ret = ADC12MEM0; // Disable ADC ADC12CTL0 &= ~ADC12ENC; // disable any conversion to allow ADC configuration ADC12CTL0 &= ~ADC12ON; // Turn off ADC return ret; } ADC adc; Loading
include/arch/msp430fr5994lp/driver/adc.h +3 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ #ifndef ADC_H #define ADC_H #include <stdint.h> class ADC { private: ADC(ADC const ©); Loading @@ -15,6 +17,7 @@ class ADC { float getTemp(); float getVCC(); uint16_t getReading(); }; extern ADC adc; Loading
src/arch/msp430fr5994lp/driver/adc.cc +33 −7 Original line number Diff line number Diff line Loading @@ -17,14 +17,13 @@ float ADC::getTemp() REFCTL0 = REFVSEL_0 | REFON; ADC12CTL0 &= ~ADC12ENC; ADC12CTL0 = ADC12SHT0_8 | ADC12ON; ADC12CTL0 = ADC12SHT0_8 | ADC12ON; // Sample and Hold: 256 ADC12CLK Cycles ADC12CTL1 = ADC12SHP; ADC12CTL3 = ADC12TCMAP; ADC12MCTL0 = ADC12VRSEL_1 | ADC12INCH_30; while(!(REFCTL0 & REFGENRDY)); ADC12CTL0 |= ADC12ENC; ADC12CTL0 |= ADC12SC; ADC12CTL0 |= ADC12ENC | ADC12SC; while (ADC12CTL1 & ADC12BUSY); ret = (float)((long)ADC12MEM0 - CALADC12_12V_30C) * (85 - 30) / Loading @@ -49,18 +48,16 @@ float ADC::getVCC() REFCTL0 = REFVSEL_1 | REFON; ADC12CTL0 &= ~ADC12ENC; ADC12CTL0 = ADC12SHT0_8 | ADC12ON; ADC12CTL0 = ADC12SHT0_8 | ADC12ON; // Sample and Hold: 256 ADC12CLK Cycles ADC12CTL1 = ADC12SHP; ADC12CTL3 = ADC12BATMAP; ADC12MCTL0 = ADC12VRSEL_1 | ADC12INCH_31; while(!(REFCTL0 & REFGENRDY)); ADC12CTL0 |= ADC12ENC; ADC12CTL0 |= ADC12SC; ADC12CTL0 |= ADC12ENC | ADC12SC; while (ADC12CTL1 & ADC12BUSY); ret = (float)ADC12MEM0 / 4096 * 2 * 2; return ret; // Disable ADC ADC12CTL0 &= ~ADC12ENC; // disable any conversion to allow ADC configuration Loading @@ -73,4 +70,33 @@ float ADC::getVCC() return ret; } uint16_t ADC::getReading() { ADC12CTL0 &= ~ADC12ENC; // disable ADC for configuration ADC12CTL0 = ADC12SHT0_8 | ADC12SHT1_8 | ADC12ON; // Sample & Hold: 64 ADC12CLK cycles; enable ADC ADC12CTL1 = ADC12SHP; // MODOSC, no prescaler ADC12CTL2 = ADC12RES_2; // 12 bit resolution ADC12CTL3 = ADC12CSTARTADD_0; // store reading in ADCMEM0 // disable output driver and input schmitt triggers on P3.0 (A12) P3SEL0 |= BIT0; P3SEL1 |= BIT0; // use default reference (AVSS / AVCC) (only required if changed by some other runtime code beforehand) // read from A12 (P3.0) ADC12MCTL0 = ADC12INCH_12; // get reading ADC12CTL0 |= ADC12ENC | ADC12SC; while (ADC12CTL1 & ADC12BUSY); uint16_t ret = ADC12MEM0; // Disable ADC ADC12CTL0 &= ~ADC12ENC; // disable any conversion to allow ADC configuration ADC12CTL0 &= ~ADC12ON; // Turn off ADC return ret; } ADC adc;