Hi all,
I am doing a project on MSP430 G2553. I am taking 150 samples from pin P1.1 at 256sps from a microphone with a pre-filter/amp, and storing them in an array. This works ok, I can see the values of the microphone voltage in the array in the debug session.
Then I want to work with the values in the array, I need to find the minimum and maximum values to start with. For this I call the `minmax` function.
The problem: In the function the LED is switched on ok at the beginning, but then the whole `for` loop is ignored, and then the LED switched off at the end of the function.
Can you see what I need to do to get the `for` loop executed to find the min and max values? Is the board in the wrong LPM level?
Please help if you can!!
Regards
Pete
The code:
// Description: A1 is sampled 256/second (ACLK/128) with reference to 1.5V.
// Timer_A is run in upmode and TA1 is used to automatically trigger
// ADC10 conversion, TA0 defines the period. Internal oscillator times sample
// (16x) and conversion (13x). Normal mode is LPM3.
#include <msp430.h>
void minmax(void); //Function prototype
unsigned int valuearray[150]; //Set up array for samples
unsigned int peakhold = 649, troughhold = 630; //Global variables for absolute min and max values
unsigned int cyclecount;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL1 = SHS_1 + CONSEQ_2 + INCH_1; // TA1 trigger sample start
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
__enable_interrupt(); // Enable interrupts.
TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 + MC_1; // TACLK = SMCLK, Up mode.
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
ADC10CTL0 |= ENC; // ADC10 Enable
ADC10AE0 |= 0x02; // P1.1 ADC10 option select
P1DIR |= 0x01; // Set P1.0 output
P1OUT &= 0x00; // Clear P1.0
TACCR0 = 128-1; // PWM Period
TACCTL1 = OUTMOD_3; // TACCR1 set/reset
TACCR1 = 127; // TACCR1 PWM Duty Cycle
TACTL = TASSEL_1 + MC_1; // ACLK, up mode
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupts
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
static int n=0; // int to count the samples
valuearray[n] = ADC10MEM; // fill up array with 150 samples
ADC10CTL1 = SHS_1 + CONSEQ_2 + INCH_1;
ADC10CTL0 |= ENC;
n++;
if (n > 149) // test sample count
{
ADC10CTL0 &= ~ENC; // disable ADC10 when 150 samples are done
minmax(); // call minmax function to find min and max values
}
}
void minmax(void)
{
P1OUT |= 0x01; // Set P1.0 LED on
for (cyclecount=0; cyclecount==149; cyclecount++) // counter for 150 samples
{
if (valuearray[cyclecount] > peakhold) // find highest value
peakhold = valuearray[cyclecount];
if (valuearray[cyclecount] < troughhold) // find lowest value
troughhold = valuearray[cyclecount];
}
P1OUT &= 0x00; // Clear P1.0 LED
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}