Hi there,
I'm currently working on a little projet with MSP430
I need to check if the current of a certain equipment drop below a value. So I use a CT with a diode and I read 0-3V = 0-10A (3phases current) if a phase loss appear, I need to light a LED.
I get a rough time to get multichannel conversion working :
I want to get 6 channels acquisition in continous mode (or one time acq. repeated like my code), my code working, but the samplig value without any input is always around 200-300 (out of 1024) for every channel. (Like if I was getting something like 0.7V)
On the other half, while using DTC how can I know (flag) when DTC transfer is done ?
This is my code :
#include <msp430.h> // *** Declaration *** int threshold = 800; // Compare Threshold void init(); // Init of MSP430G2332 unsigned int ADC_Value[6]; //Array of value from ADC (6 channels) unsigned int Current[6]; //Max value in the last second unsigned int j=0; // Used for loop unsigned int Div =0; // Time divider unsigned int i=0; // // *** Main routine *** int main(void) { init(); while(1) { } } // // Timer A0 interrupt service routine #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A (void) { if (Div >= 1000) { //P1OUT ^= BIT6; // Toggle P1.6 Div =0; if ((Current[0] > threshold) || (Current[1] > threshold) || (Current[2] > threshold)) { P1OUT |= BIT6; } else { P1OUT &= ~BIT6; } if ((Current[3] > threshold) || (Current[4] > threshold) || (Current[5] > threshold)) { P1OUT |= BIT7; } else { P1OUT &= ~BIT7; } Current[0] =0; Current[1] =0; Current[2] =0; Current[3] =0; Current[4] =0; Current[5] =0; } //__bic_SR_register_on_exit(CPUOFF); ADC10CTL0 &= ~ENC; while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active ADC10SA = (int)ADC_Value; // Data buffer start (Current 5 = channel 0, acq from 5 to 0) for (j=0;j<6;j++) { if (ADC_Value[j] > Current[j]) { Current[j] = ADC_Value[j]; } } //__delay_cycles(50); Div++; ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion ready //__bis_SR_register(CPUOFF + GIE); } #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { } void init(void) { //WATCHDOG TIMER WDTCTL = WDTPW + WDTHOLD; // Stop WDT // PIN SET // P1DIR |= BIT0; // P1OUT &= BIT1; P1DIR |= BIT6; // P1.6 output // P1DIR |= BIT0; // TIMER SETUP TACCTL0 = CCIE; // TIMER COUNTER INTERRUPT ENABLE TACCR0 = 1; // COUNTER PERIOD TIME (12KHZ ~ 12000 = 1SEC) BCSCTL3 = LFXT1S_2; // ACLK = 12KHZ VLO CLOCK TACTL = TASSEL_1 + MC_1; // ACLK (VLO) COUNT UP TO CCRO //ADC SETUP ADC10CTL0 = SREF_0 + ADC10IE + ADC10ON + ADC10SHT_2; // Ref = Vcc , Interrupt Enabled, ADCON ADC10CTL1 = CONSEQ_1 + ADC10SSEL_0 + INCH_5; // Multi-Channel, single acq, from 5 to 0 ADC10AE0 |= 0b111111; // Enable pin as analog ADC10DTC1 = 0x06; // Number of channel ADC10CTL0 |= ENC + ADC10SC + MSC; // Enable conversion, start conversion, multi channel //LOW POWER MODE + GLOBAL INTERRUPT ON // __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt __enable_interrupt(); // Enable interrupts. return; }