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.

MSP430F5438A-EP: ADC12 Timer trigger

Part Number: MSP430F5438A-EP

Hello! everyone.

I want to trigger the ADC12 with Timer B. 

My plan is Timer B triggers ADC12 about once per 0.1 second. 

I configurated the timer B and ADC12. But it didnt worked. where am i missing?

I understood if i SHS in ADC12CTL1 is '10' (TIMER B),  ADC12 work every 0.1 seconds.

Did i get it wrong?

My code was working only the first conversion is performed, then not working.

This is my code under the text.

Timer B = UpMode, ACLK, output = toogle      ADC12 = A0, Single channel single-conversion, Vref = 2.5V

ACLK = 32,768 Hz     

TB0CCR0 = 3275;  
TB0CTL |= TIMER_B_MC_UP + TIMER_B_TBSSEL_ACLK;
TB0CCTL0 = TIMER_B_CCIE+TIMER_B_OUTMOD_4;
TB0CTL |= TIMER_B_TBCLR;

P6SEL |= BIT0;
REFCTL0|= REFON + REFMSTR + REFVSEL_2 + REFTCOFF;

ADC12CTL0 |= ADC12ON + ADC12SHT0_2;
ADC12CTL1 |= ADC12SHS_2 + ADC12SHP;
ADC12MCTL0 |= ADC12SREF_1;
ADC12IE |= ADC12IE0;
ADC12CTL0 |= ADC12SHS_2 + ADC12ENC;

// temp variable = Global variable
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_A_ISR(void)
{
	static int i =0;
    switch(_even_in_range(ADC12IV, 0x24))
		{
			case 0x06:
			    if(i==10) i = 0;
			    temp[i++] = ADC12MEM0;
				break;
			default:
				break;
		}
}

Not using ADC12SC. Because it's not precise.

Anyone help me~!

  • When using SHS>0, you need to toggle ADC12ENC (=0 then =1) after each conversion in order to get the next trigger [Ref User Guide (SLAU208Q)  Sec 28.2.7.1]. The ADC ISR is usually a good place to do this.

    -------------------

    Unsolicited:

    > TB0CCTL0 = TIMER_B_CCIE+TIMER_B_OUTMOD_4;

    This enables the CCR0 interrupt, but I don't see an ISR (TIMER0_B0_VECTOR) for it. If you're not interested in the timer interrupt, try:

    > TB0CCTL0 = TIMER_B_OUTMOD_4;

    OUTMOD=4 (toggle) output runs at half the timer cycle rate, so I expect you're getting a trigger every 0.2 sec. You might want to set TB0CCR0=3275/2.

    -----------------

    > ADC12CTL0 |= ADC12SHS_2 + ADC12ENC;

    The SHS field is in CTL1, not CTL0. This is actually setting SHT0 to something large. Try instead:

    > ADC12CTL0 |= ADC12ENC;

  • Thank you for your answer.

    I corrected the wrong part after hearing your advice.

    1. Quotation (SLAU208Q Sec 28.2.7.1] : 'When any other trigger source is used, ADC12ENC must be toggled between each conversion"

    I missed the sentence. 

    => I revised  ADC12ENC is toggled in ADC12ISR.

    #pragma vector = ADC12_VECTOR
    __interrupt void ADC12_ISR(void)
    {
    	static int i =0;
        switch(_even_in_range(ADC12IV, 0x24))
    		{
    			case 0x06:
    			    if(i==10) {i = 0;}
    				while(ADC12CTL1 & ADC12BUSY);
    			    adc12v.temp[i++] = ADC12MEM0;
    				break;
    			default:
    				break;
    		}
    	ADC12CTL0 &= ~(ADC12ENC);
    	ADC12CTL0 |= ADC12ENC;
    }

    2. Timer Interrupt

    => In this question, I didn't write time ISR. But in my code, it was in time ISR. 

    #pragma vector = TIMER0_B0_VECTOR
    __interrupt void TIMER0_B0_ISR(void)
    {
    	P7OUT ^= BIT7; // LED 
    }

    3. OUTPUT 0.1s

    => I revised TB0CCR0 = 1638-1;

    4. ADC12CTL0 |= ADC12SHS_2 + ADC12ENC

    => I revised  ADC12CTL0 |= ADC12ENC.

    As a result, The ADC is working.

**Attention** This is a public forum