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.

ADC on MSP430 with one constant reading and one occasionally

Other Parts Discussed in Thread: MSP430F5529

Greetings

I would like to know how to switch between a simple ADC conversion from 1 analog input and a sequence of conversión from 2 analog inputs, for 2 current sensors with MSP430F5529.

I need to have the reading of only one sensor each second, and the reading of both sensors each 5 minutes. Currently I'm making the reading of both sensors each second, but the idea is save resources through ignoring one reading until the next 5 minutes. There's my ADC code:

#include <msp430.h>
#include "ADC.h"

/*

* LOCAL VARIABLES

*/
volatile unsigned int current1;
volatile unsigned int current2;

/*

* FUNCTIONS

*/

void
initADC(void)
{
P6SEL = 0x0F; // Enable A/D channel inputs
ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_2; // Turn on ADC12, set sampling time
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_1; // Use sampling timer, single sequence
ADC12MCTL0 = ADC12INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = ADC12INCH_1+ADC12EOS; // ref+=AVcc, channel = A1, end seq.
ADC12IE = ADC12IFG1; // Enable ADC12IFG.1
ADC12CTL0 |= ADC12ENC; // Enable conversions
__bis_SR_register(GIE); // Enable interrupts

return;
}

void getADC(int * currents){

ADC12CTL0 |= ADC12SC;

currents[0]=current1;
currents[1]=current2;

ADC12CTL0 &= ~ADC12SC;

return;
}


/*
* INTERRUPTIONS
*/

#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR(void)
{

switch(__even_in_range(ADC12IV,34))

{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: break; // Vector 6: ADC12IFG0
case 8: // Vector 8: ADC12IFG1
current1 = ADC12MEM0; // Move results, IFG is cleared
current2 = ADC12MEM1; // Move results, IFG is cleared
__bic_SR_register_on_exit(LPM4_bits); // Exit active CPU, SET BREAKPOINT HERE
break;

case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}

Thank you for your attention, every suggestion is welcome. Have a nice day.

  • You have to introduce timer (interrupt) which starts ADC sequence each 5 minutes. Also you shall understand that after setting ADC12SC bit, result of sampling both ADC channels is not immediately available. You shall introduce some waiting for ADC conversion completion.

    Studying source code examples usually helps.

**Attention** This is a public forum