1000 pennies for your thoughts

I wrote a little program for the TI eZ430-F2013. It might surprise you. But then it might not. I would like to hear your thoughts about this.

Around July 4th (2006) midnight, I will pick one of the replies (if any) that I think is the best, and send its author a $10 Spark-Fun gift certificate.

<QUOTE>

> /***************************************
> 
> *
> 
> * A funny little LED Flasher
> 
> * For the TI eZ430-F2013 Kit
> 
> *
> 
> * You may need to read TI's
> 
> * Application Report slaa294.pdf
> 
> * "MSP430 Software Coding Techniques"
> 
> * to understand what I mean
> 
> *
> 
> ***************************************/
> 
> 
> 
> #include <msp430x20x3.h>
> 
> 
> 
> short int tmr_flag, wdt_flag;
> 
> 
> 
> void main(void)
> 
> {
> 
> int i;
> 
> 
> 
> _BIS_SR(OSCOFF);
> 
> 
> 
> P1OUT = 0;
> 
> P1DIR = 0x01;
> 
> P1REN = ~0x01;
> 
> P2OUT = 0;
> 
> P2REN = 0xFF;
> 
> P2SEL = 0;
> 
> 
> 
> for (i = 50; i>0; i--);
> 
> 
> 
> DCOCTL = CALDCO_1MHZ;
> 
> BCSCTL1 = CALBC1_1MHZ;
> 
> BCSCTL2 = DIVS_3;
> 
> 
> 
> WDTCTL = WDTPW + WDTTMSEL + WDTIS0;
> 
> IE1 |= WDTIE;
> 
> 
> 
> TACCR0 = 8192;
> 
> TACTL = TASSEL_2 + MC_1;
> 
> TACCTL0 = CCIE;
> 
> 
> 
> while(1)
> 
> {
> 
> _BIS_SR(CPUOFF + GIE);
> 
> 
> 
> if (tmr_flag)
> 
> {
> 
> tmr_flag = 0;
> 
> P1OUT |= 0x02;
> 
> for (i = 600; i>0; i--);
> 
> P1OUT &= ~0x02;
> 
> } //end of if
> 
> 
> 
> else if (wdt_flag)
> 
> {
> 
> wdt_flag = 0;
> 
> P1OUT |= 0x01;
> 
> for (i = 600; i>0; i--);
> 
> P1OUT &= ~0x01;
> 
> } //end of else if
> 
> 
> 
> } // end of while
> 
> 
> 
> } // end of main
> 
> 
> 
> #pragma vector=TIMERA0_VECTOR
> 
> __interrupt void tmr (void)
> 
> {
> 
> tmr_flag = 1;
> 
> _BIC_SR_IRQ(CPUOFF);
> 
> }
> 
> 
> 
> #pragma vector=WDT_VECTOR
> 
> __interrupt void wdt (void)
> 
> {
> 
> wdt_flag = 1;
> 
> _BIC_SR_IRQ(CPUOFF);
> 
> }
> 
> 
> 
> //*** The End **************************

</QUOTE>

intriguing… too bad i killed my EZ430

Actually, you can use almost any TI MSP430 chip. It does not have to be eZ430-F2013.

(1) For eZ430-F2013, there is a LED at P1.0. Furthermore, P1.0 high turns the LED on; P1.0 low turns the LED off. You have to modify the code according to your hardware.

(2) All other I/O pins should also be configured so that they are not left floating or fighting with external connections. For eZ430-2013, my code makes all of them as input pins with a weak on-chip pull-down. You do not have to do this.

(3) The code does not need ACLK. Having one will not hurt.

(4) DCO should be programmed to approximately 1 MHz. This is not critical.

I don’t have an ez430, so I can’t run this, and I don’t have IAR so I can’t check the assembly, but this is how I read it:

Both the watchdog timer and timer A are set to trigger their interrupts after 8192 clocks, and since the WDT is started first, that interrupt should come in first. It looks like this code may be non-deterministic.

In the main loop you stop execution until you are woken up in an interrupt. If you were woken by timer a you clear the flag, set p1.1, spin for n * 600 clocks (how does IAR interpret for(i=600;i;i–)? mspgcc would ignore it since it is dead code, executing a nop in the loop would make mspgcc keep it) where n is the number of clocks required to complete the loop, clear p1.1, and loop back to the start where we go to sleep.

If the watchdog timer woke us up we clear the flag, set p1.0 (turning on the LED), spin for the same time as above, then clear p1.0 (turning off the LED). Then we loop back to the start and go to sleep again.

In both of the interrupt vectors we set the respective flag and wake the procedssor up.

From looking over your code it looks like the only result of an interrupt from timer A (assuming nothing’s on 11.1) is that a flash of the LED might be missed if both timer a and the wdt call an interrupt near the same time.

The LED should flash for 600 uS (or is it 1.2 mS? or something else?) every 8.2 mS

I’ve never used the WDT, so I may be completely off, but that’s how I read it.

Ian,

Thank you for your thoughts. I ordered a Gift Certificate for you – order conformation #7357. Could you contact Spak Fun Electronics to get it?


You are correct. The little program has two major problems.

(1) The LED will flash only if you set compiler optimization to "None" or "Low".

(2) It will flash for about 8min+20sec, stop flashing for about 40sec, and repeat this sequence.

Thanks!

It’s nice to find someone who calls me by name instead of my username.

They should’ve sent you the gift certificate code. You can send it to me through a PM.

Ian