I'm having issues taking readings from the ADC10MEM of the MSP430G2231.
I'm taking ADC readings from 2 pins. One has a small voltage, the other is connected to ground (I'm just testing out hte ADC). When I read the ADC10MEM register in IAR, the values seem very random compared with what I expect to be reading (for both inputs). Also, they change (seemingly sporadically) when I step through the program. I expect the ADC to turn off after its taken its reading (using single conversion mode) and so I don't understand why this might occur. IAR said that simply reading the register could cause its value to change, but I'm not sure what they mean by this.
Also, I'd like to move my ADC10MEM value into working registers in order to use the values in calculations. However, the values written to the working registers do not consistently match what I'm seeing in the ADC10MEM register. How do I ensure the exact ADC10MEM value is being written to the working registers?
Has anyone had similar issues setting up the ADC? Or have any insight into how to fix my issues?
Thank you
Joanna
#include "msp430g2231.h"
BitTest EQU 0001
ORG 0x0200
DELAYCOUNT DS 2
INPUTSELECT DS 2
;-------------------------------------------------------------------------------
ORG 0FC00h
;-------------------------------------------------------------------------------
RESET mov.w #0280h,SP
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL
mov.w #TASSEL_2+MC_2,&TACTL
SETUP_PINS bis.b #010h,&P1DIR
bis.b #010h,&P1SEL
SETUP_CLOCK mov.w #01110100b,&DCOCTL_
mov.w #10001111b,&BCSCTL1_
mov.w #00000000b,&BCSCTL2_
and.w #11111101b,&IE1_
CLEAR_RAM clr.w R4
clr.w R5
clr.w INPUTSELECT
MAINLOOP bit.w #BitTest,INPUTSELECT
jnc CAPINPUT
bic.b #BIT6,&P1OUT
ZEROINPUT mov.w #INCH_0,&ADC10CTL1
clrc
jmp DELAY1
CAPINPUT mov.w #INCH_1,&ADC10CTL1
clrc
DELAY1 add.b #0001b,DELAYCOUNT
jnc DELAY1
mov.w ADC10SHT_0+ADC10SHT_0+ADC10ON,&ADC10CTL0
mov.w #ADC10SSEL_3+SHS_1+CONSEQ_3,&ADC10CTL1
DELAYTRIAL add.b #0001b,DELAYCOUNT
jnc DELAYTRIAL
bis.b #BIT0,&ADC10AE0
bis.w #ENC+ADC10SC,&ADC10CTL0
bis.b #BIT6,&P1OUT
clrc
DELAY2 add.b #0001b,DELAYCOUNT
jnc DELAY2
bic.b #BIT6,&P1OUT
bit.w #BitTest,INPUTSELECT
jnc CAPINPUTMEMORY
ZEROINPUTMEMORY mov.w &ADC10MEM,R4
inc.w INPUTSELECT
jmp MAINLOOP
CAPINPUTMEMORY mov.w &ADC10MEM,R5
inc.w INPUTSELECT
jmp MAINLOOP
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
ORG 0FFFEh ; MSP430 RESET Vector
DW RESET ;
END