Tool/software: Code Composer Studio
Hello,
I wrote the following code below to get MSP430 to go into LPM3 and then wake up through a timer interrupt. I give different values to the timer each time it goes to sleep mode. The frequency (both Main clock and Aux clock) is 10kHz so I expect the sleep period to be 1s, 2s, 3s, 4s and 5s in that order.
I'm measuring this by measuring the current on a digital multimeter which samples every 40us. I use the significantly high active mode current to figure out the delay (during which the device was in LPM3 and consumed much lower current) and the numbers I get are 1.1s, 2.2s, 2.6s, 3.2s and 4.2s. The multimeter was connected between the power supply and the microcontroller.
I used the debug mode to see what was happening to the registers and despite setting the clear flag, it doesn't look like it actually gets set in the TB0CTL register. Also, every time I enter or exit LPM3, the TB0CTL register changes - I'm unsure if that is expected to happen or not. The values I see in the TB0R register immediately after the timer interrupt seems very random too. It was taking too long on debug mode so I changed the values on the TB0CCR0 register to be 10, 20, 30, 40 and 50 instead of 10000, 20000 and so on (to be able to test it). When I switch back to the original numbers (the ones in the code below), TB0R doesn't seem to take any of these bigger values, I only see it go to 26 at some point in the middle and was surprisingly quick unlike the first time I tried it.
I'm unsure where the error is right now. Essentially I want to be able to reset the TB0R register every time I start a new count and I want to be able to see that count when I plot the current - I'm unsure where I'm going wrong with this.
Any help, or prod in the right direction would be greatly appreciated.
Here's the code that I'm using:
#include <msp430.h>
int num_packets = 0, j, count;
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
CSCTL4 = SELA__VLOCLK | SELMS__VLOCLK;
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
P1OUT = 0x00; P2OUT = 0x00;
P3OUT = 0x00; P4OUT = 0x00;
P5OUT = 0x00; P6OUT = 0x00;
P1DIR = 0xff; P2DIR = 0xff;
P3DIR = 0xff; P4DIR = 0xff;
P5DIR = 0xff; P6DIR = 0xff;
// P1DIR |= BIT0;
// P1OUT |= BIT0;
//Set timer
TB0CCTL0 = CCIE | CLLD_0; //Added CLLD bits
// TB0CTL = MC_1|ID_0|TBSSEL_1|TBCLR; //set up timer and start it
TB0CTL = ID_0|TBSSEL_1|TBCLR;
TB0R = 0x0;
TB0CCR0 = 10000;
TB0CTL |= MC_1;
__bis_SR_register(LPM3_bits | GIE);
TB0CTL = ID_0|TBSSEL_1|TBCLR;
TB0R = 0x0;
TB0CCR0 = 20000;
TB0CTL |= MC_1;
__bis_SR_register(LPM3_bits | GIE);
TB0CTL = ID_0|TBSSEL_1|TBCLR;
TB0R = 0x0;
TB0CCR0 = 30000;
TB0CTL |= MC_1;
__bis_SR_register(LPM3_bits | GIE);
TB0CTL = ID_0|TBSSEL_1|TBCLR;
TB0R = 0x0;
TB0CCR0 = 40000;
TB0CTL |= MC_1;
__bis_SR_register(LPM3_bits | GIE);
TB0CTL = ID_0|TBSSEL_1|TBCLR;
TB0R = 0x0;
TB0CCR0 = 50000;
TB0CTL |= MC_1;
__bis_SR_register(LPM3_bits | GIE);
/*
for(num_packets = 0; num_packets < 5; num_packets++)
{
TB0CTL = MC_1|ID_0|TBSSEL_1|TBCLR; //set up timer and start it
// P1OUT &= ~BIT0;
//enter lpm3
TB0CCR0 = 10000*(num_packets + 1); // Set Timer Period
__bis_SR_register(LPM3_bits | GIE);
__no_operation();
}
*/
// P1OUT = 1;
}
#pragma vector = TIMER0_B0_VECTOR
__interrupt void TB0_ISR (void)
{
__bic_SR_register_on_exit(LPM3_bits | GIE);
TB0CTL &= ~MC_3; // Turn off Timer - edited from ~MC_1 to ~MC_3 so that the MC bits go to 00
}
Thanks,
Yaman