Part Number: MSP430F2012
Can someone shed some light on something stupid I must be doing....Below is code...pwrDetect = 1...I am using a scope to monitor the LEDs and the A/D input (from where I can see a dip in the voltage on this pin when I am sampling). In any event in the TIMERA0_VECTOR if I remove the ...LPM3 line I seem to see a sample every 5 seconds, if I have that line in there I get a sample every 2 seconds?? Can someone please tell me why I am not getting a sample every second.....I have the A/D clock at 1MHz with a /64 sampling period. The timer runs off of VLO clock which after measuring it on a pin I set up the period for about 1 second.
#include <msp430f2012.h>
#include "LiPo.h"
volatile unsigned int ledSw = 0;
volatile unsigned int pwrDetect = 0;
unsigned int startup = 1;
volatile unsigned int *pBattVolt;
void main(void)
{
struct PWM_F201x pwm;
mcuWatchdogOff;
mcu_clk_setup;
configIO;
AD_Config();
pBattVolt = &ADC10MEM;
pwm.Period = 11600; pwm.OnTime = 9400; pwm.mode = reset; pwm.cycle = up;
pwm_config(&pwm);
TACCTL0 |= CCIE;
ADC10CTL0 |= ENC + ADC10SC;
while (1){
__bis_SR_register(LPM3_bits + GIE);
//setting PWM to flash or not depending on switches thrown
if (pwrDetect == 1) { //pwr connected LEDs work off of timer
P1OUT &= ~(BIT2 | BIT6); //LEDs off
P1OUT |= BIT7; //MOSFETs on
//based on analog voltage the P1SEL will choose which LED flashes off of timer
//**************************
if (*pBattVolt < RED_LIMIT){
P1SEL = ((P1SEL & ~YELLOW) | RED);
}
else if (*pBattVolt > GREEN_LIMIT_CHG){
P1SEL = ((P1SEL & ~YELLOW) | GREEN);
}
else{
P1SEL |= YELLOW;
}
TACCTL1 = OUTMOD_3;
}
else{ //pwr not connected LEDs work off switch NOT timer
P1OUT &= ~BIT7; //MOSFETs off
if ((ledSw) == 1){ //led switch thrown
P1SEL = 0;
if (*pBattVolt < RED_LIMIT){
P1OUT &= ~YELLOW;
P1OUT |= RED;
}
else if (*pBattVolt > GREEN_LIMIT){
P1OUT &= ~YELLOW;
P1OUT |= GREEN;
}
else{
P1OUT |= YELLOW;
}
TACCTL1 = OUTMOD_1;
}
else if ((P1IN & BIT0) == 0){
P1OUT &= ~(BIT6 | BIT2);
P1SEL = 0;
}
}
}
}
#pragma vector=TIMERA0_VECTOR
__interrupt void PWM_Output_Control(void)
{
ADC10CTL0 |= ENC + REFON + ADC10ON + ADC10SC; //arm ADC for sample
// __bic_SR_register_on_exit(LPM3_bits); //wake up and run main!
}
#pragma vector=ADC10_VECTOR
__interrupt void BatteryVoltage(void)
{
ADC10CTL0 &= ~(ENC + REFON + ADC10ON); // disable ADC
*pBattVolt = ADC10MEM;
if (startup){
P1IFG |= BIT5; //force interrupt to get pwr status
P1IFG |= BIT0; //force interrupt to get LED switch
}
__bic_SR_register_on_exit(LPM3_bits); //wake up and run main!
}
#pragma vector=PORT1_VECTOR
__interrupt void LED_Switch(void)
{
if (P1IFG & BIT0){
ledSw = P1IN & BIT0;
P1IFG &= ~BIT0;
P1IES ^= BIT0;
}
if (P1IFG & BIT5){
pwrDetect = (P1IN & BIT5) >> 5;
P1IFG &= ~BIT5;
P1IES ^= BIT5;
}
startup = 0;
__bic_SR_register_on_exit(LPM3_bits); //wake up and run main!
}
Function definitions
void AD_Config(void) //definition
{
ADC10CTL0 = SREF_1 + REF2_5V + ADC10SHT_3 + REFON + ADC10IE + ADC10ON;
ADC10CTL1 = INCH_1 + SHS_0 + ADC10DIV_0 + ADC10SSEL_2; //channel 1, clk (3.7MHz - 6.3MHz), divide clk by 8 to guarantee settling with HiZ input, TA1 source S/H
ADC10AE0 = BIT1;
}
void pwm_config(struct PWM_F201x* p) //definition
{
TACCR0 = ( p -> Period ); //Period in Sec
TACCR1 = ( p -> OnTime ); // On time in Sec
if (p -> mode == normal)
TACCTL1 |= OUTMOD_3;
else if (p -> mode == invert)
TACCTL1 |= OUTMOD_7;
else if (p -> mode == reset)
TACCTL1 |= OUTMOD_5;
else
TACCTL1 |= OUTMOD_3;
if (p -> cycle == up)
TACTL |= MC_1;
else
TACTL |= MC_2;
TACTL |= TASSEL_1;
}
BCSCTL3 |= 0x20; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ;
thanks