I am currently writing my first serious application with an MSP430 controller (specifically, an MSP430G2553) and I am a bit confused by the documentation as to how I'm supposed to set up the ADC10. I want to use it like this:
- The signal (coming from a 100 kΩ potentiometer between VCC and GND) is connected to input A4 (pin 6) and is in range from GND to VCC
- Once in a while (when the user presses a button) I want to sample the voltage at that input. One sample is sufficient.
- I have enough time to do whatever is needed to sample input when the time to do so arrives.
- I'd prefer to do this synchronously (i.e. without interrupts) as to not complicate the program logic too much.
- The ADC10 should be turned off when I'm not using it to conserve power.
- Neither the ADC10 nor ping 6 is used in any other way in this application.
How do I configure and use the ADC10 in this use case? I am programming the MSP430 in assembly, but an answer in C is useful, too.
Here is how I think the ADC is supposed to be configured:
ADC10CTL0: SREFx = 000 (V_CC) ADC10SHTx = 11 (64 clocks, we have enough time) ADC10SR = 1 (50 kbps should be enough) REFOUT = 0 REFBURST = don't care MSC = don't care REF2_5V = don't care REFON = 0 ADC10ON = 1 (set to 1 after finishing the configuration) ADC10IE = 0 (no interrupts) ADC10CTL1 INCHx = 0100 (A4) SHSx = 00 (sample and hold sourced from ADC10SC) ADC10DF = 0 (no two's complement) ISSH = 0 (no inversion) ADC10DIVx = 000 (not too sure either) ADC10SSELx = 0 (is this the right clock?) CONSEQx = 00 (single channel single conversion) ADC10AE0 = 0x10 (A4 enabled) ADC10DTC1 = 0 (DTC disabled)
I think the sequence to sample data looks like this:
ADC10SCto 0 and configure all the registers.
ENCto 10 to start conversion
- wait for 64 + 12 + 1 = 77 cycles for conversion to finish
- read result from
Is this sequence correct? Are the settings correct?