This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430FR6989: ANALOG INPUT/OUTPUT with BoosterPack EDUMKII

Part Number: MSP430FR6989

Tool/software: Code Composer Studio

If I want multiple ADC signals from multiple analog inputs, in which variables can I store them? ( So while setting up ADC, I currently have: 

                                                                                           

SetupADC12 mov.w #ADC12SHT0_2+ADC12ON,&ADC12CTL0 ; 16x
                      bis.w #ADC12SHP,&ADC12CTL1 ; ADCCLK = MODOSC; sampling timer
                      bis.w #ADC12RES_2,&ADC12CTL2 ; 12-bit conversion results
                      bis.w #ADC12INCH_1,&ADC12MCTL0; A1 ADC input select; Vref=AVCC
                      bis.w #ADC12IE0,&ADC12IER0 ; Enable ADC conv complete interrupt

If I want another ADC signal, how do I declare that? And in the ADC Interrupt Service Routine, how do I distinguish between the different ADC signals?

Thanks in advance. 

  • You probably want something like:

    SetupADC12 mov.w #ADC12SHT0_2+ADC12ON+ADC12MSC,&ADC12CTL0 ; 16x, on, MSC=1
               bis.w #ADC12SHP+ADC12CONSEQ_1,&ADC12CTL1 ; ADCCLK = MODOSC; sampling timer, CONSEQ=1
               bis.w #ADC12RES_2,&ADC12CTL2 ; 12-bit conversion results
               bis.w #ADC12INCH_1,&ADC12MCTL0; A1 ADC input select; Vref=AVCC
               bis.w #ADC12INCH_2+ADC12EOS,&ADC12MCTL1; A2 ADC input select; Vref=AVCC., end of list
               bis.w #ADC12IE1,&ADC12IER0 ; Enable ADC conv complete interrupt
    
    

    This will put the A1 result in ADC12MEM0 and A2 result in ADC12MEM1. It will interrupt when the second conversion is finished. 

  • I know it's been a while but are you sure there is no missing code in your reply? Because with the setup above the code always jumps to the code for ADCMEM1 interrupt (and hence execute MEM1) no matter what. This is how my setup looks right now: (I am trying to activate both the horizontal and vertical axis for the joystick)


    ;P9.2 is horizontal joystick axis A10 is the ADC signal
    ;P8.7 is vertical joystick axis A4 is the ADC signal
    
    
    SetupP9 bis.b #BIT2,&P9SEL0 ;
    bis.b #BIT2,&P9SEL1 ;
    SetupP8 bis.b #BIT7,&P8SEL0 ;
    bis.b #BIT7,&P9SEL1 ;
    
    
    SetupADC12 mov.w #ADC12SHT0_2+ADC12ON+ADC12MSC,&ADC12CTL0 ; 16x
    bis.w #ADC12SHP+ADC12CONSEQ_1,&ADC12CTL1 ; ADCCLK = MODOSC; sampling timer
    bis.w #ADC12RES_2,&ADC12CTL2 ; 12-bit conversion results
    bis.w #ADC12INCH_10,&ADC12MCTL0; A10 ADC input select; Vref=AVCC
    bis.w #ADC12INCH_4+ADC12EOS,&ADC12MCTL1
    bis.w #ADC12IE1,&ADC12IER0 ; Enable ADC conv complete interrupt
    
    Mainloop mov.w #2500,R15 ; Delay ~5000 cycles between conversions
    L1 dec.w R15 ; Decrement R15
    jnz L1 ; Delay over?
    bis.w #ADC12ENC+ADC12SC,&ADC12CTL0 ; Start sampling/conversion
    nop ;
    bis.w #LPM0+GIE,SR ; Enter LPM0 w/ interrupt
    nop ; for debug
    jmp Mainloop ; Again
    nop
    
    ;-------------------------------------------------------------------------------
    ADC12_ISR; ADC12 interrupt service routine
    ;-------------------------------------------------------------------------------
    add.w &ADC12IV,PC ; add offset to PC
    reti ; Vector 0: No interrupt
    reti ; Vector 2: ADC12MEMx Overflow
    reti ; Vector 4: Conversion time overflow
    reti ; Vector 6: ADC12HI
    reti ; Vector 8: ADC12LO
    reti ; Vector 10: ADC12IN
    jmp MEM0 ; Vector 12: ADC12MEM0 Interrupt
    jmp MEM1 ; Vector 14: ADC12MEM1
    reti ; Vector 16: ADC12MEM2
    reti ; Vector 18: ADC12MEM3
    reti ; Vector 20: ADC12MEM4
    reti ; Vector 22: ADC12MEM5
    reti ; Vector 24: ADC12MEM6
    reti ; Vector 26: ADC12MEM7
    reti ; Vector 28: ADC12MEM8
    reti ; Vector 30: ADC12MEM9
    reti ; Vector 32: ADC12MEM10
    reti ; Vector 34: ADC12MEM11
    reti ; Vector 36: ADC12MEM12
    reti ; Vector 38: ADC12MEM13
    reti ; Vector 40: ADC12MEM14
    reti ; Vector 42: ADC12MEM15
    reti ; Vector 44: ADC12MEM16
    reti ; Vector 46: ADC12MEM17
    reti ; Vector 48: ADC12MEM18
    reti ; Vector 50: ADC12MEM19
    reti ; Vector 52: ADC12MEM20
    reti ; Vector 54: ADC12MEM21
    reti ; Vector 56: ADC12MEM22
    reti ; Vector 58: ADC12MEM23
    reti ; Vector 60: ADC12MEM24
    reti ; Vector 62: ADC12MEM25
    reti ; Vector 64: ADC12MEM26
    reti ; Vector 66: ADC12MEM27
    reti ; Vector 68: ADC12MEM28
    reti ; Vector 70: ADC12MEM29
    reti ; Vector 72: ADC12MEM30
    reti ; Vector 74: ADC12MEM31
    reti ; Vector 76: ADC12RDY
    
    MEM1
    ;Do MEM1 Stuff
    bic.w #LPM0,0(SP)
    reti
    
    MEM0 
    ;Do MEM0 stuff
    bic.w #LPM0,0(SP)
    reti
    
    ;------------------------------------------------------------------------------
    ; Interrupt Vectors
    ;------------------------------------------------------------------------------
    .sect ".reset" ; MSP430 RESET Vector
    .short RESET ;
    .sect ADC12_VECTOR ; ADC12 Vector
    .short ADC12_ISR ;
    .end

  • Part Number: MSP430FR6989

    Tool/software: Code Composer Studio

    I am trying to set-up the code to activate both the horizontal and vertical axis of the joystick on a BoosterPack MKII attached to my MSP430FR6989 Launchpad (by setting ADC signals to the pins controlling the horizontal and vertical axes). With the setup I have now, the code always jumps to the code for ADCMEM1 interrupt (and hence execute MEM1) no matter what. This is how my setup looks right now: Please let me know what is possibly causing the code to always jump to MEM1. 



    ;P9.2 is horizontal joystick axis A10 is the ADC signal
    ;P8.7 is vertical joystick axis A4 is the ADC signal
    
    
    SetupP9 bis.b #BIT2,&P9SEL0 ;
    bis.b #BIT2,&P9SEL1 ;
    SetupP8 bis.b #BIT7,&P8SEL0 ;
    bis.b #BIT7,&P9SEL1 ;
    
    
    SetupADC12 mov.w #ADC12SHT0_2+ADC12ON+ADC12MSC,&ADC12CTL0 ; 16x
    bis.w #ADC12SHP+ADC12CONSEQ_1,&ADC12CTL1 ; ADCCLK = MODOSC; sampling timer
    bis.w #ADC12RES_2,&ADC12CTL2 ; 12-bit conversion results
    bis.w #ADC12INCH_10,&ADC12MCTL0; A10 ADC input select; Vref=AVCC
    bis.w #ADC12INCH_4+ADC12EOS,&ADC12MCTL1
    bis.w #ADC12IE1,&ADC12IER0 ; Enable ADC conv complete interrupt
    
    Mainloop mov.w #2500,R15 ; Delay ~5000 cycles between conversions
    L1 dec.w R15 ; Decrement R15
    jnz L1 ; Delay over?
    bis.w #ADC12ENC+ADC12SC,&ADC12CTL0 ; Start sampling/conversion
    nop ;
    bis.w #LPM0+GIE,SR ; Enter LPM0 w/ interrupt
    nop ; for debug
    jmp Mainloop ; Again
    nop
    
    ;-------------------------------------------------------------------------------
    ADC12_ISR; ADC12 interrupt service routine
    ;-------------------------------------------------------------------------------
    add.w &ADC12IV,PC ; add offset to PC
    reti ; Vector 0: No interrupt
    reti ; Vector 2: ADC12MEMx Overflow
    reti ; Vector 4: Conversion time overflow
    reti ; Vector 6: ADC12HI
    reti ; Vector 8: ADC12LO
    reti ; Vector 10: ADC12IN
    jmp MEM0 ; Vector 12: ADC12MEM0 Interrupt
    jmp MEM1 ; Vector 14: ADC12MEM1
    reti ; Vector 16: ADC12MEM2
    reti ; Vector 18: ADC12MEM3
    reti ; Vector 20: ADC12MEM4
    reti ; Vector 22: ADC12MEM5
    reti ; Vector 24: ADC12MEM6
    reti ; Vector 26: ADC12MEM7
    reti ; Vector 28: ADC12MEM8
    reti ; Vector 30: ADC12MEM9
    reti ; Vector 32: ADC12MEM10
    reti ; Vector 34: ADC12MEM11
    reti ; Vector 36: ADC12MEM12
    reti ; Vector 38: ADC12MEM13
    reti ; Vector 40: ADC12MEM14
    reti ; Vector 42: ADC12MEM15
    reti ; Vector 44: ADC12MEM16
    reti ; Vector 46: ADC12MEM17
    reti ; Vector 48: ADC12MEM18
    reti ; Vector 50: ADC12MEM19
    reti ; Vector 52: ADC12MEM20
    reti ; Vector 54: ADC12MEM21
    reti ; Vector 56: ADC12MEM22
    reti ; Vector 58: ADC12MEM23
    reti ; Vector 60: ADC12MEM24
    reti ; Vector 62: ADC12MEM25
    reti ; Vector 64: ADC12MEM26
    reti ; Vector 66: ADC12MEM27
    reti ; Vector 68: ADC12MEM28
    reti ; Vector 70: ADC12MEM29
    reti ; Vector 72: ADC12MEM30
    reti ; Vector 74: ADC12MEM31
    reti ; Vector 76: ADC12RDY
    
    MEM1
    ;Do MEM1 Stuff
    bic.w #LPM0,0(SP)
    reti
    
    MEM0 
    ;Do MEM0 stuff
    bic.w #LPM0,0(SP)
    reti
    
    ;------------------------------------------------------------------------------
    ; Interrupt Vectors
    ;------------------------------------------------------------------------------
    .sect ".reset" ; MSP430 RESET Vector
    .short RESET ;
    .sect ADC12_VECTOR ; ADC12 Vector
    .short ADC12_ISR ;
    .end

  • Hello Adwaya,

    I've merged your newest thread with this one as they seem to be the same subject matter. Please keep the current topic being discussed to this thread.

    Also, when posting code onto the forum, please use the code formatting tool marked by the </> button. This tool can be located by clicking the "Insert Code, Attach Files, and more" link on the bottom right hand side of the Reply menu. The Code Formatting Tool allows the code to be easily read and can help you get support faster on the forums. I've modified your previous post to reflect the use of the tool.
  • Per User Guide (SLAU367O) section 34.2.14.1, the ADC12IFGx flags aren't cleared by reading the IV. (That makes them different from pretty much all other IV clients.) You need to read the corresponding MEMx register, else the IFG will remain and the interrupt will just keep recurring.

    Add something to your MEM1 code to read (at least) ADC12MEM1 to clear the IFG. As I mentioned, you'll only get one interrupt (for MEM1), so in general you'll want to do something with ADC12MEM0 at the same time.
  • Hmm interesting. So I checked the values in both ADCMEM0 and ADCMEM1 while it went to the MEM1 (after I moved the joystick a certain way) and yeah there are reasonable values stored in both variables. So basically I don't even need the MEM0 seperation? (I can move the MEM0 code in MEM1 too?) Why does that happen? Why can I read a value in ADCMEM0 although the code jumps to MEM1? What if I were to use even more ADC signals (suppose the accelerometer)? How would I implement the new ADC signals then?
  • > bis.w #ADC12IE1,&ADC12IER0 ; Enable ADC conv complete interrupt
    This sets IE1, so it will (only) interrupt after MEM0 and MEM1 are done (MEM0 to MEM1 are done in order). You could set IE0 as well, then you would get two separate interrupts, but that is rarely useful since they usually happen in quick succession.

    You wanted to sample multiple channels. The combination of CONSEQ=1, MSC=1, MCTL1, EOS, and IE1 does that for you. If you wanted a third channel, you would add MCTL2 (move the EOS there), switch from IE1 to IE2, and use a different case in the ISR. (Keep CONSEQ=1 and MSC=1.)

    I encourage you to look over User Guide (SLAU367O) Fig. 34-9. There's a lot in there.
  • Thanks a lot that worked out perfectly!

**Attention** This is a public forum