MSP430Why Keliang’s code maybe did

Download Report

Transcript MSP430Why Keliang’s code maybe did

Why Keliang’s code maybe did
(or maybe didn’t)
work
… or High (impedance) Anxiety
The code
void main(void){
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= 0x01;
TACTL |= TASSEL_1 + ID_0 + MC_1;
TACCR0 = 6000;
CCTL0 = CCIE;
_BIS_SR(LPM3_bits + GIE);
//
//
//
//
//
//
Kill Watchdog
P1.0 output
Select ACLK, select up mode, select divider to be 1
Count up to 12000
CCR0 interrupt enabled
Go into lpm3 and enable interrupts
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= 0x01;
}
// Toggle P1.0
The idea was to use VLO clock (about 12 kHz) to generate interrupts after every 6000 counts
When running on Launchpad the interrupts were happening about twice as fast as expected,
but specs say VLO can be as high as 20 kHz so this seemed OK.
When running on daughterboard, code didn’t work at all. Light would sometimes flash
depending on touching circuit…
Setting pin 2.6 as output also stopped code from working (even on Launchpad)
Timer A module
TACTL |= TASSEL_1 + ID_0 + MC_1;
TACCR0 = 6000;
CCTL0 = CCIE;
// Select ACLK, select up mode, select divider to be 1
// Count up to 12000
// CCR0 interrupt enabled
Clock Module
At power up LXFT1Sx=00 so input is from XIN.
XIN/P2.6
(Page 3 of datasheet)
(Page 53 of datasheet)
(Page 341 of User’s Guide)
P2Sel.6 = 1, P2Sel.7=1
P2Sel2.6=0, P2Sel2.7=0
Pin 19 is XIN
XIN is input (high impedance)!
Touching (or getting near) pins can change value. That explains daughterboard behavior.
Making P2.6 an output keeps line from oscillating , so light didn’t blink. This explains part of
Launchpad behavior.
But why did code work otherwise on Launchpad (though faster than expected)?
Launchpad PCB
Front (as seen from front)
Back (as seen from front)
0Ω resistors
Test line from debugger
Test line from debugger oscillates at 25kHz (a bit more than max on VLO freq of 20 kHz).
Capacitance between Test and P2.6 (XIN) caused it to oscillate. Putting finger on PCB near
P2.6 stopped light from blinking because of extra capacitance (voltage divider).
Also – powering Launchpad from battery (so debugger isn’t on) stopped program from
working.
The Fix
void main(void){
WDTCTL = WDTPW + WDTHOLD;
// Kill Watchdog
P1DIR |= 0x01;
// P1.0 output
TACTL |= TASSEL_1 + ID_0 + MC_1; // Select ACLK, select up mode, select divider to be 1
TACCR0 = 6000;
// Count up to 12000
CCTL0 = CCIE;
// CCR0 interrupt enabled
BCSCTL3 |= BIT5;
// Set ACLK to be VLO
_BIS_SR(LPM3_bits + GIE);
// Go into lpm3 and enable interrupts
}