EmbeddedRelated.com
Forums

LED On & Off for two interrupt

Started by shskurkra June 20, 2010
Working on a LED to switch On and Off for two interrupt. First for switch, second for timer interrupt. Tried to figure out the error, but could figure. The code does not produce the desired output. Can anyone help me. Here is the code. Thank you.

#include
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P2SEL = 0x00; // Port 2 pins are unused
P2OUT = 0x00;
P2DIR = 0x00;
P2REN = 0xFF;
P1DIR = Bit6; // P1.6 output, else input
P1OUT = Bit4; // P1.4 set, else reset
P1REN |= Bit4; // P1.4 pullup
P1IE |= Bit4; // P1.4 interrupt enabled
P1IES |= Bit4; // P1.4 Hi/lo edge
P1IFG &= ~Bit4; // P1.4 IFG cleared

BCSCTL1= CALBC1_16MHZ;
DCOCTL= CALDCO_16MHZ;

TACTL= MC_0 | TASSEL_1 | ID_3 | TACLR; // reset it, first.
TCCTL0= CM_0 | CCIS_2 | SCS | OUTMOD_1 | CCIE; // set the mode.
TACCR0= 19999; // 10ms intervals.
TACTL= MC_1 | TASSEL_1 | ID_3; // turn it on.

_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt

}

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= 0x40; // P1.6 = toggle
P1IFG &= ~0x10; // P1.4 IFG cleared

}

// TimerA interrupt service routine
#pragma vector= TIMERA0_VECTOR
__interrupt void timer_A0( void ) {
static int counter= 550;

if ( --counter == 0 ) {
P1OUT &= ~0x40; // using XOR toggles the pin value
}
}

Beginning Microcontrollers with the MSP430

> Working on a LED to switch On and Off for two interrupt. First for switch,
> second for timer interrupt. Tried to figure out the error, but could
> figure. The code does not produce the desired output. Can anyone help me.
> Here is the code. Thank you.
For this it would be nice to know what is the desired output. More, it is
essential to figure out what's wrong with the programme.

Waldemar

Hi Waldemar,

Thank you for responding to my post.

The desired output is, MSP is in low power mode 3, Active clock (ACLK) and ACLK is divided by 8 by the Internal Divider to get the timer interrupt for software delay greater than 16-bit. Also using a tactile switch to turn LED "On" and turn LED "Off".

First, MSP430 is in LPM3, waiting for switch to be pressed to turn LED "On". Once, switch is pressed and LED turns "On", simultaneously triggers timer to start counting in Up mode up-to TACCR0 value by comparing to CCIS (that is GND). Once LED is turned "On" program returns to LPM3 and waits for next interrupt to turn LED "Off".

The next part is interesting because program will continuously waits either for "switch interrupt" and "timer interrupt" to turn back LED "Off". If switch is pressed before timer interrupt, makes LED to turn "Off" or if switch is not pressed before timer interrupt, makes LED to turn "Off". I did not use "if" or "while" loop to turn LED "Off" because LPM3 waits for interrupt to turn back LED "Off".

After turning LED "Off", MSP430 goes to LPM3 waiting for switch interrupt to turn LED "On" and timer is reset. Please help me to obtain the output.

Thank you in advance.
I looked to TI application notes for switch interrupt
--- In m..., "Waldemar Krzok" wrote:
>
> > Working on a LED to switch On and Off for two interrupt. First for switch,
> > second for timer interrupt. Tried to figure out the error, but could
> > figure. The code does not produce the desired output. Can anyone help me.
> > Here is the code. Thank you.
> For this it would be nice to know what is the desired output. More, it is
> essential to figure out what's wrong with the programme.
>
> Waldemar
>

It seems to me that there is a problem in "meeting of the minds". One mind wants some desired output. Another one wrote the code. Yet another one wrote the comments of the code.
_________

To the one who wants some desired output.

You hired the wrong guys to do the job.
_________

To the one who wrote the code.

Why do you set the DCO to generate 16MHz? For what reason?

What is the frequency of ACLK? For that matter, does ACLK exist?

In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
_________

And, to the one who wrote the comments.

You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.

You also need to know a little about the hardware. For example, if there is an ACLK at 32768Hz, TimerA will count at the rate of 4096 c/s. It will take not just 10 ms, but almost 5 seconds to count 20000. That means it will take about 3 quarters of an hour to do your first "using XOR toggles the pin value". There after, it will take about 88 hours to repeat that again.

--- In m..., "shskurkra" wrote:
>
> Hi Waldemar,
>
> Thank you for responding to my post.
>
> The desired output is, MSP is in low power mode 3, Active clock (ACLK) and ACLK is divided by 8 by the Internal Divider to get the timer interrupt for software delay greater than 16-bit. Also using a tactile switch to turn LED "On" and turn LED "Off".
>
> First, MSP430 is in LPM3, waiting for switch to be pressed to turn LED "On". Once, switch is pressed and LED turns "On", simultaneously triggers timer to start counting in Up mode up-to TACCR0 value by comparing to CCIS (that is GND). Once LED is turned "On" program returns to LPM3 and waits for next interrupt to turn LED "Off".
>
> The next part is interesting because program will continuously waits either for "switch interrupt" and "timer interrupt" to turn back LED "Off". If switch is pressed before timer interrupt, makes LED to turn "Off" or if switch is not pressed before timer interrupt, makes LED to turn "Off". I did not use "if" or "while" loop to turn LED "Off" because LPM3 waits for interrupt to turn back LED "Off".
>
> After turning LED "Off", MSP430 goes to LPM3 waiting for switch interrupt to turn LED "On" and timer is reset. Please help me to obtain the output.
>
> Thank you in advance.
> I looked to TI application notes for switch interrupt
> --- In m..., "Waldemar Krzok" wrote:
> >
> > > Working on a LED to switch On and Off for two interrupt. First for switch,
> > > second for timer interrupt. Tried to figure out the error, but could
> > > figure. The code does not produce the desired output. Can anyone help me.
> > > Here is the code. Thank you.
> >
> >
> > For this it would be nice to know what is the desired output. More, it is
> > essential to figure out what's wrong with the programme.
> >
> > Waldemar
>

Thanks OCY.

> Why do you set the DCO to generate 16MHz? For what reason?

In LPM3 SMCLK and DCO are disabled. DCO should not be used in this program. Thanks OCY for pointing the extra code's in program.

> What is the frequency of ACLK? For that matter, does ACLK exist?

I'm using eZ430-F2013. ACLK need to be sourced from VLO which is typically 4 to 20 KHz (varies from chip to chip). ACLK can be assigned from VLO by "BCSCTL3 |= LFXT1S_2;" code. From MSP430 basics textbook, ACLK can be accessed by-->
BCSCTL3 |= LFXT1S_2; //ACLK = VLO
P2SEL = 0x00;
P2DIR = 0x00;
P2REN = BIT6 | BIT7; <--

> In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?

TACCTL0 = CCIE = 1; //Capture/Compare timer interrupt is enabled
CCIS = 2 ; //Select Input for TACCR0, GND is the input signal
SCS = 1; //To Synchronous the capture with timer clcok
OUTMOD=1 //Compare output mode is set to discharge LED by generating interrupt

To generate interrupt after counting until the value stored in TACCR0.
I need to change CCIS = 3; because Vcc will be my input for TACCR0 and counts until 19999. Once the value is reached, TACCTL0 generates a interrupt to turn LED "Off". VLO runs at 4KHz, TACCTLO take 5 seconds to generate the interrupt (for turning "Off" LED)

> You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.

Forgot to change the comment. The comment should be "turn Off LED" instead of toggle LED.

I need the desired output, please provide suggestions to program. Thank you in advance.
--- In m..., "old_cow_yellow" wrote:
>
> It seems to me that there is a problem in "meeting of the minds". One mind wants some desired output. Another one wrote the code. Yet another one wrote the comments of the code.
> _________
>
> To the one who wants some desired output.
>
> You hired the wrong guys to do the job.
> _________
>
> To the one who wrote the code.
>
> Why do you set the DCO to generate 16MHz? For what reason?
>
> What is the frequency of ACLK? For that matter, does ACLK exist?
>
> In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> _________
>
> And, to the one who wrote the comments.
>
> You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
>
> You also need to know a little about the hardware. For example, if there is an ACLK at 32768Hz, TimerA will count at the rate of 4096 c/s. It will take not just 10 ms, but almost 5 seconds to count 20000. That means it will take about 3 quarters of an hour to do your first "using XOR toggles the pin value". There after, it will take about 88 hours to repeat that again.
>
> --- In m..., "shskurkra" wrote:
> >
> > Hi Waldemar,
> >
> > Thank you for responding to my post.
> >
> > The desired output is, MSP is in low power mode 3, Active clock (ACLK) and ACLK is divided by 8 by the Internal Divider to get the timer interrupt for software delay greater than 16-bit. Also using a tactile switch to turn LED "On" and turn LED "Off".
> >
> > First, MSP430 is in LPM3, waiting for switch to be pressed to turn LED "On". Once, switch is pressed and LED turns "On", simultaneously triggers timer to start counting in Up mode up-to TACCR0 value by comparing to CCIS (that is GND). Once LED is turned "On" program returns to LPM3 and waits for next interrupt to turn LED "Off".
> >
> > The next part is interesting because program will continuously waits either for "switch interrupt" and "timer interrupt" to turn back LED "Off". If switch is pressed before timer interrupt, makes LED to turn "Off" or if switch is not pressed before timer interrupt, makes LED to turn "Off". I did not use "if" or "while" loop to turn LED "Off" because LPM3 waits for interrupt to turn back LED "Off".
> >
> > After turning LED "Off", MSP430 goes to LPM3 waiting for switch interrupt to turn LED "On" and timer is reset. Please help me to obtain the output.
> >
> > Thank you in advance.
> >
> >
> > I looked to TI application notes for switch interrupt
> > --- In m..., "Waldemar Krzok" wrote:
> > >
> > > > Working on a LED to switch On and Off for two interrupt. First for switch,
> > > > second for timer interrupt. Tried to figure out the error, but could
> > > > figure. The code does not produce the desired output. Can anyone help me.
> > > > Here is the code. Thank you.
> > >
> > >
> > > For this it would be nice to know what is the desired output. More, it is
> > > essential to figure out what's wrong with the programme.
> > >
> > > Waldemar
> > >
>

--- In m..., "shskurkra" wrote:
>
> Thanks OCY.
>
> > Why do you set the DCO to generate 16MHz? For what reason?
>
> In LPM3 SMCLK and DCO are disabled. DCO should not be used in this program. Thanks OCY for pointing the extra code's in program.
>
> > What is the frequency of ACLK? For that matter, does ACLK exist?
>
> I'm using eZ430-F2013. ACLK need to be sourced from VLO which is typically 4 to 20 KHz (varies from chip to chip). ACLK can be assigned from VLO by "BCSCTL3 |= LFXT1S_2;" code.

*** But you did not do that, thus currently you have no ACLK.
*** TimerA has nothing to count

> From MSP430 basics textbook, ACLK can be accessed by-->
> BCSCTL3 |= LFXT1S_2; //ACLK = VLO
> P2SEL = 0x00;
> P2DIR = 0x00;
> P2REN = BIT6 | BIT7; <--
>
> > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
>
> TACCTL0 = CCIE = 1; //Capture/Compare timer interrupt is enabled
> CCIS = 2 ; //Select Input for TACCR0, GND is the input signal
> SCS = 1; //To Synchronous the capture with timer clcok
> OUTMOD=1 //Compare output mode is set to discharge LED by
> generating interrupt
>
> To generate interrupt after counting until the value stored
> in TACCR0.
> I need to change CCIS = 3; because Vcc will be my input for
> TACCR0 and counts until 19999. Once the value is reached,
> TACCTL0 generates a interrupt to turn LED "Off". VLO runs at
> 4KHz, TACCTLO take 5 seconds to generate the interrupt (for
> turning "Off" LED)

*** To generate interrupt, all you need is CCIE. The other bits
*** do nothing in your situation.

*** If you use VLO as ACLK, it will take 15 seconds to generate
*** one interrupt.

*** Initially you need 550 interrupts before you turn off the LED.
*** There after, you need 65536 interrupts for that to happen again.

*** So you need to watch the LED for weeks and then find out that
*** you do not have an ACLK.

>
> > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
>
> Forgot to change the comment. The comment should be "turn Off
> LED" instead of toggle LED.

*** Ok, but how did you turn on the LED? The P1 ISR toggles it.
*** How do you know if it will turn on or off?
>
> I need the desired output, please provide suggestions to program. Thank you in advance.
> --- In m..., "old_cow_yellow" wrote:
> >
> > It seems to me that there is a problem in "meeting of the minds". One mind wants some desired output. Another one wrote the code. Yet another one wrote the comments of the code.
> > _________
> >
> > To the one who wants some desired output.
> >
> > You hired the wrong guys to do the job.
> > _________
> >
> > To the one who wrote the code.
> >
> > Why do you set the DCO to generate 16MHz? For what reason?
> >
> > What is the frequency of ACLK? For that matter, does ACLK exist?
> >
> > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> > _________
> >
> > And, to the one who wrote the comments.
> >
> > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
> >
> > You also need to know a little about the hardware. For example, if there is an ACLK at 32768Hz, TimerA will count at the rate of 4096 c/s. It will take not just 10 ms, but almost 5 seconds to count 20000. That means it will take about 3 quarters of an hour to do your first "using XOR toggles the pin value". There after, it will take about 88 hours to repeat that again.
> >
> > --- In m..., "shskurkra" wrote:
> > >
> > > Hi Waldemar,
> > >
> > > Thank you for responding to my post.
> > >
> > > The desired output is, MSP is in low power mode 3, Active clock (ACLK) and ACLK is divided by 8 by the Internal Divider to get the timer interrupt for software delay greater than 16-bit. Also using a tactile switch to turn LED "On" and turn LED "Off".
> > >
> > > First, MSP430 is in LPM3, waiting for switch to be pressed to turn LED "On". Once, switch is pressed and LED turns "On", simultaneously triggers timer to start counting in Up mode up-to TACCR0 value by comparing to CCIS (that is GND). Once LED is turned "On" program returns to LPM3 and waits for next interrupt to turn LED "Off".
> > >
> > > The next part is interesting because program will continuously waits either for "switch interrupt" and "timer interrupt" to turn back LED "Off". If switch is pressed before timer interrupt, makes LED to turn "Off" or if switch is not pressed before timer interrupt, makes LED to turn "Off". I did not use "if" or "while" loop to turn LED "Off" because LPM3 waits for interrupt to turn back LED "Off".
> > >
> > > After turning LED "Off", MSP430 goes to LPM3 waiting for switch interrupt to turn LED "On" and timer is reset. Please help me to obtain the output.
> > >
> > > Thank you in advance.
> > >
> > >
> > > I looked to TI application notes for switch interrupt
> > > --- In m..., "Waldemar Krzok" wrote:
> > > >
> > > > > Working on a LED to switch On and Off for two interrupt. First for switch,
> > > > > second for timer interrupt. Tried to figure out the error, but could
> > > > > figure. The code does not produce the desired output. Can anyone help me.
> > > > > Here is the code. Thank you.
> > > >
> > > >
> > > > For this it would be nice to know what is the desired output. More, it is
> > > > essential to figure out what's wrong with the programme.
> > > >
> > > > Waldemar
> > > >
> > >
>

> *** To generate interrupt, all you need is CCIE. The other bits
> *** do nothing in your situation.

I require other bits like SIS, OUTMOD..etc for PWM, duty cycle. Thanks for mentioning. It is helpful to know.

> *** If you use VLO as ACLK, it will take 15 seconds to generate
> *** one interrupt.
>
> *** Initially you need 550 interrupts before you turn off the LED.
> *** There after, you need 65536 interrupts for that to happen again.
>
> *** So you need to watch the LED for weeks and then find out that
> *** you do not have an ACLK.

Using VLO as ACLK, one interrupt take 15 seconds, because TACCR0 = 19999; Then, counter value should be replaced by 1 instead of 550.

> *** Ok, but how did you turn on the LED? The P1 ISR toggles it.

ACLK should start (generate interrupt) only if LED is turn ON from switch (connected to P1.4).

> *** How do you know if it will turn on or off?

For this, I need to monitor P1.4. I think "if loop" will take care of monitoring P1.4 and Timer interrupt to turn switch "Off". I did not insert a loop in my previous program because I was generating two interrupt simultaneously. Hardware interrupt has higher priority over software interrupt.

OCY, I will try the above and post the outcome. Thank you for your comments. It as helpful.
--- In m..., "old_cow_yellow" wrote:
>
> --- In m..., "shskurkra" wrote:
> >
> > Thanks OCY.
> >
> > > Why do you set the DCO to generate 16MHz? For what reason?
> >
> > In LPM3 SMCLK and DCO are disabled. DCO should not be used in this program. Thanks OCY for pointing the extra code's in program.
> >
> > > What is the frequency of ACLK? For that matter, does ACLK exist?
> >
> > I'm using eZ430-F2013. ACLK need to be sourced from VLO which is typically 4 to 20 KHz (varies from chip to chip). ACLK can be assigned from VLO by "BCSCTL3 |= LFXT1S_2;" code.
>
> *** But you did not do that, thus currently you have no ACLK.
> *** TimerA has nothing to count
>
> > From MSP430 basics textbook, ACLK can be accessed by-->
> > BCSCTL3 |= LFXT1S_2; //ACLK = VLO
> > P2SEL = 0x00;
> > P2DIR = 0x00;
> > P2REN = BIT6 | BIT7; <--
> >
> > > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> >
> > TACCTL0 = CCIE = 1; //Capture/Compare timer interrupt is enabled
> > CCIS = 2 ; //Select Input for TACCR0, GND is the input signal
> > SCS = 1; //To Synchronous the capture with timer clcok
> > OUTMOD=1 //Compare output mode is set to discharge LED by
> > generating interrupt
> >
> > To generate interrupt after counting until the value stored
> > in TACCR0.
> > I need to change CCIS = 3; because Vcc will be my input for
> > TACCR0 and counts until 19999. Once the value is reached,
> > TACCTL0 generates a interrupt to turn LED "Off". VLO runs at
> > 4KHz, TACCTLO take 5 seconds to generate the interrupt (for
> > turning "Off" LED)
>
> *** To generate interrupt, all you need is CCIE. The other bits
> *** do nothing in your situation.
>
> *** If you use VLO as ACLK, it will take 15 seconds to generate
> *** one interrupt.
>
> *** Initially you need 550 interrupts before you turn off the LED.
> *** There after, you need 65536 interrupts for that to happen again.
>
> *** So you need to watch the LED for weeks and then find out that
> *** you do not have an ACLK.
>
> >
> > > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
> >
> > Forgot to change the comment. The comment should be "turn Off
> > LED" instead of toggle LED.
>
> *** Ok, but how did you turn on the LED? The P1 ISR toggles it.
> *** How do you know if it will turn on or off?
> >
> > I need the desired output, please provide suggestions to program. Thank you in advance.
> >
> >
> > --- In m..., "old_cow_yellow" wrote:
> > >
> > > It seems to me that there is a problem in "meeting of the minds". One mind wants some desired output. Another one wrote the code. Yet another one wrote the comments of the code.
> > > _________
> > >
> > > To the one who wants some desired output.
> > >
> > > You hired the wrong guys to do the job.
> > > _________
> > >
> > > To the one who wrote the code.
> > >
> > > Why do you set the DCO to generate 16MHz? For what reason?
> > >
> > > What is the frequency of ACLK? For that matter, does ACLK exist?
> > >
> > > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> > > _________
> > >
> > > And, to the one who wrote the comments.
> > >
> > > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
> > >
> > > You also need to know a little about the hardware. For example, if there is an ACLK at 32768Hz, TimerA will count at the rate of 4096 c/s. It will take not just 10 ms, but almost 5 seconds to count 20000. That means it will take about 3 quarters of an hour to do your first "using XOR toggles the pin value". There after, it will take about 88 hours to repeat that again.
> > >
> > > --- In m..., "shskurkra" wrote:
> > > >
> > > > Hi Waldemar,
> > > >
> > > > Thank you for responding to my post.
> > > >
> > > > The desired output is, MSP is in low power mode 3, Active clock (ACLK) and ACLK is divided by 8 by the Internal Divider to get the timer interrupt for software delay greater than 16-bit. Also using a tactile switch to turn LED "On" and turn LED "Off".
> > > >
> > > > First, MSP430 is in LPM3, waiting for switch to be pressed to turn LED "On". Once, switch is pressed and LED turns "On", simultaneously triggers timer to start counting in Up mode up-to TACCR0 value by comparing to CCIS (that is GND). Once LED is turned "On" program returns to LPM3 and waits for next interrupt to turn LED "Off".
> > > >
> > > > The next part is interesting because program will continuously waits either for "switch interrupt" and "timer interrupt" to turn back LED "Off". If switch is pressed before timer interrupt, makes LED to turn "Off" or if switch is not pressed before timer interrupt, makes LED to turn "Off". I did not use "if" or "while" loop to turn LED "Off" because LPM3 waits for interrupt to turn back LED "Off".
> > > >
> > > > After turning LED "Off", MSP430 goes to LPM3 waiting for switch interrupt to turn LED "On" and timer is reset. Please help me to obtain the output.
> > > >
> > > > Thank you in advance.
> > > >
> > > >
> > > > I looked to TI application notes for switch interrupt
> > > > --- In m..., "Waldemar Krzok" wrote:
> > > > >
> > > > > > Working on a LED to switch On and Off for two interrupt. First for switch,
> > > > > > second for timer interrupt. Tried to figure out the error, but could
> > > > > > figure. The code does not produce the desired output. Can anyone help me.
> > > > > > Here is the code. Thank you.
> > > > >
> > > > >
> > > > > For this it would be nice to know what is the desired output. More, it is
> > > > > essential to figure out what's wrong with the programme.
> > > > >
> > > > > Waldemar
> > > > >
> > > >
> > >
>

Thanks OCY program is working, but without accurate timing.

I tried with ACLK, the timer is not accurate. Error is +2 to +4 seconds from required time. Can I use SMCLK instead of ACLK, while is LPM3? From my understanding, SMCLK is disabled in LPM3.

Thank you.

--- In m..., "shskurkra" wrote:
>
> > *** To generate interrupt, all you need is CCIE. The other bits
> > *** do nothing in your situation.
>
> I require other bits like SIS, OUTMOD..etc for PWM, duty cycle. Thanks for mentioning. It is helpful to know.
>
> > *** If you use VLO as ACLK, it will take 15 seconds to generate
> > *** one interrupt.
> >
> > *** Initially you need 550 interrupts before you turn off the LED.
> > *** There after, you need 65536 interrupts for that to happen again.
> >
> > *** So you need to watch the LED for weeks and then find out that
> > *** you do not have an ACLK.
>
> Using VLO as ACLK, one interrupt take 15 seconds, because TACCR0 = 19999; Then, counter value should be replaced by 1 instead of 550.
>
> > *** Ok, but how did you turn on the LED? The P1 ISR toggles it.
>
> ACLK should start (generate interrupt) only if LED is turn ON from switch (connected to P1.4).
>
> > *** How do you know if it will turn on or off?
>
> For this, I need to monitor P1.4. I think "if loop" will take care of monitoring P1.4 and Timer interrupt to turn switch "Off". I did not insert a loop in my previous program because I was generating two interrupt simultaneously. Hardware interrupt has higher priority over software interrupt.
>
> OCY, I will try the above and post the outcome. Thank you for your comments. It as helpful.
> --- In m..., "old_cow_yellow" wrote:
> >
> >
> >
> > --- In m..., "shskurkra" wrote:
> > >
> > > Thanks OCY.
> > >
> > > > Why do you set the DCO to generate 16MHz? For what reason?
> > >
> > > In LPM3 SMCLK and DCO are disabled. DCO should not be used in this program. Thanks OCY for pointing the extra code's in program.
> > >
> > > > What is the frequency of ACLK? For that matter, does ACLK exist?
> > >
> > > I'm using eZ430-F2013. ACLK need to be sourced from VLO which is typically 4 to 20 KHz (varies from chip to chip). ACLK can be assigned from VLO by "BCSCTL3 |= LFXT1S_2;" code.
> >
> > *** But you did not do that, thus currently you have no ACLK.
> > *** TimerA has nothing to count
> >
> > > From MSP430 basics textbook, ACLK can be accessed by-->
> > > BCSCTL3 |= LFXT1S_2; //ACLK = VLO
> > > P2SEL = 0x00;
> > > P2DIR = 0x00;
> > > P2REN = BIT6 | BIT7; <--
> > >
> > > > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> > >
> > > TACCTL0 = CCIE = 1; //Capture/Compare timer interrupt is enabled
> > > CCIS = 2 ; //Select Input for TACCR0, GND is the input signal
> > > SCS = 1; //To Synchronous the capture with timer clcok
> > > OUTMOD=1 //Compare output mode is set to discharge LED by
> > > generating interrupt
> > >
> > > To generate interrupt after counting until the value stored
> > > in TACCR0.
> > > I need to change CCIS = 3; because Vcc will be my input for
> > > TACCR0 and counts until 19999. Once the value is reached,
> > > TACCTL0 generates a interrupt to turn LED "Off". VLO runs at
> > > 4KHz, TACCTLO take 5 seconds to generate the interrupt (for
> > > turning "Off" LED)
> >
> > *** To generate interrupt, all you need is CCIE. The other bits
> > *** do nothing in your situation.
> >
> > *** If you use VLO as ACLK, it will take 15 seconds to generate
> > *** one interrupt.
> >
> > *** Initially you need 550 interrupts before you turn off the LED.
> > *** There after, you need 65536 interrupts for that to happen again.
> >
> > *** So you need to watch the LED for weeks and then find out that
> > *** you do not have an ACLK.
> >
> > >
> > > > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
> > >
> > > Forgot to change the comment. The comment should be "turn Off
> > > LED" instead of toggle LED.
> >
> > *** Ok, but how did you turn on the LED? The P1 ISR toggles it.
> > *** How do you know if it will turn on or off?
> > >
> > > I need the desired output, please provide suggestions to program. Thank you in advance.
> > >
> > >
> > > --- In m..., "old_cow_yellow" wrote:
> > > >
> > > > It seems to me that there is a problem in "meeting of the minds". One mind wants some desired output. Another one wrote the code. Yet another one wrote the comments of the code.
> > > > _________
> > > >
> > > > To the one who wants some desired output.
> > > >
> > > > You hired the wrong guys to do the job.
> > > > _________
> > > >
> > > > To the one who wrote the code.
> > > >
> > > > Why do you set the DCO to generate 16MHz? For what reason?
> > > >
> > > > What is the frequency of ACLK? For that matter, does ACLK exist?
> > > >
> > > > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> > > > _________
> > > >
> > > > And, to the one who wrote the comments.
> > > >
> > > > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
> > > >
> > > > You also need to know a little about the hardware. For example, if there is an ACLK at 32768Hz, TimerA will count at the rate of 4096 c/s. It will take not just 10 ms, but almost 5 seconds to count 20000. That means it will take about 3 quarters of an hour to do your first "using XOR toggles the pin value". There after, it will take about 88 hours to repeat that again.
> > > >
> > > > --- In m..., "shskurkra" wrote:
> > > > >
> > > > > Hi Waldemar,
> > > > >
> > > > > Thank you for responding to my post.
> > > > >
> > > > > The desired output is, MSP is in low power mode 3, Active clock (ACLK) and ACLK is divided by 8 by the Internal Divider to get the timer interrupt for software delay greater than 16-bit. Also using a tactile switch to turn LED "On" and turn LED "Off".
> > > > >
> > > > > First, MSP430 is in LPM3, waiting for switch to be pressed to turn LED "On". Once, switch is pressed and LED turns "On", simultaneously triggers timer to start counting in Up mode up-to TACCR0 value by comparing to CCIS (that is GND). Once LED is turned "On" program returns to LPM3 and waits for next interrupt to turn LED "Off".
> > > > >
> > > > > The next part is interesting because program will continuously waits either for "switch interrupt" and "timer interrupt" to turn back LED "Off". If switch is pressed before timer interrupt, makes LED to turn "Off" or if switch is not pressed before timer interrupt, makes LED to turn "Off". I did not use "if" or "while" loop to turn LED "Off" because LPM3 waits for interrupt to turn back LED "Off".
> > > > >
> > > > > After turning LED "Off", MSP430 goes to LPM3 waiting for switch interrupt to turn LED "On" and timer is reset. Please help me to obtain the output.
> > > > >
> > > > > Thank you in advance.
> > > > >
> > > > >
> > > > > I looked to TI application notes for switch interrupt
> > > > > --- In m..., "Waldemar Krzok" wrote:
> > > > > >
> > > > > > > Working on a LED to switch On and Off for two interrupt. First for switch,
> > > > > > > second for timer interrupt. Tried to figure out the error, but could
> > > > > > > figure. The code does not produce the desired output. Can anyone help me.
> > > > > > > Here is the code. Thank you.
> > > > > >
> > > > > >
> > > > > > For this it would be nice to know what is the desired output. More, it is
> > > > > > essential to figure out what's wrong with the programme.
> > > > > >
> > > > > > Waldemar
> > > > > >
> > > > >
> > > >
> > >
>

From you previous message I understand you are using the VLO as ACLK.
The VLO is a simple RC oscillator and is absolutely not reliable
timing-wise. Connect a real crystal to the XIN/XOUT of your controller
to get more accurate timing. A watch crystal of 32768Hz would be a good
option here. Don't forget to configure the required port registers to
enable the crystal.
You cannot use SMCLK in LPM3, but ACLK remains active.

Hans
On Tue, 22 Jun 2010 05:12:35 -0000
"shskurkra" wrote:

> Thanks OCY program is working, but without accurate timing.
>
> I tried with ACLK, the timer is not accurate. Error is +2 to +4 seconds from required time. Can I use SMCLK instead of ACLK, while is LPM3? From my understanding, SMCLK is disabled in LPM3.
>
> Thank you.
>
> --- In m..., "shskurkra" wrote:
> >
> > > *** To generate interrupt, all you need is CCIE. The other bits
> > > *** do nothing in your situation.
> >
> > I require other bits like SIS, OUTMOD..etc for PWM, duty cycle. Thanks for mentioning. It is helpful to know.
> >
> > > *** If you use VLO as ACLK, it will take 15 seconds to generate
> > > *** one interrupt.
> > >
> > > *** Initially you need 550 interrupts before you turn off the LED.
> > > *** There after, you need 65536 interrupts for that to happen again.
> > >
> > > *** So you need to watch the LED for weeks and then find out that
> > > *** you do not have an ACLK.
> >
> > Using VLO as ACLK, one interrupt take 15 seconds, because TACCR0 = 19999; Then, counter value should be replaced by 1 instead of 550.
> >
> > > *** Ok, but how did you turn on the LED? The P1 ISR toggles it.
> >
> > ACLK should start (generate interrupt) only if LED is turn ON from switch (connected to P1.4).
> >
> > > *** How do you know if it will turn on or off?
> >
> > For this, I need to monitor P1.4. I think "if loop" will take care of monitoring P1.4 and Timer interrupt to turn switch "Off". I did not insert a loop in my previous program because I was generating two interrupt simultaneously. Hardware interrupt has higher priority over software interrupt.
> >
> > OCY, I will try the above and post the outcome. Thank you for your comments. It as helpful.
> >
> >
> > --- In m..., "old_cow_yellow" wrote:
> > >
> > >
> > >
> > > --- In m..., "shskurkra" wrote:
> > > >
> > > > Thanks OCY.
> > > >
> > > > > Why do you set the DCO to generate 16MHz? For what reason?
> > > >
> > > > In LPM3 SMCLK and DCO are disabled. DCO should not be used in this program. Thanks OCY for pointing the extra code's in program.
> > > >
> > > > > What is the frequency of ACLK? For that matter, does ACLK exist?
> > > >
> > > > I'm using eZ430-F2013. ACLK need to be sourced from VLO which is typically 4 to 20 KHz (varies from chip to chip). ACLK can be assigned from VLO by "BCSCTL3 |= LFXT1S_2;" code.
> > >
> > > *** But you did not do that, thus currently you have no ACLK.
> > > *** TimerA has nothing to count
> > >
> > > > From MSP430 basics textbook, ACLK can be accessed by-->
> > > > BCSCTL3 |= LFXT1S_2; //ACLK = VLO
> > > > P2SEL = 0x00;
> > > > P2DIR = 0x00;
> > > > P2REN = BIT6 | BIT7; <--
> > > >
> > > > > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> > > >
> > > > TACCTL0 = CCIE = 1; //Capture/Compare timer interrupt is enabled
> > > > CCIS = 2 ; //Select Input for TACCR0, GND is the input signal
> > > > SCS = 1; //To Synchronous the capture with timer clcok
> > > > OUTMOD=1 //Compare output mode is set to discharge LED by
> > > > generating interrupt
> > > >
> > > > To generate interrupt after counting until the value stored
> > > > in TACCR0.
> > > > I need to change CCIS = 3; because Vcc will be my input for
> > > > TACCR0 and counts until 19999. Once the value is reached,
> > > > TACCTL0 generates a interrupt to turn LED "Off". VLO runs at
> > > > 4KHz, TACCTLO take 5 seconds to generate the interrupt (for
> > > > turning "Off" LED)
> > >
> > > *** To generate interrupt, all you need is CCIE. The other bits
> > > *** do nothing in your situation.
> > >
> > > *** If you use VLO as ACLK, it will take 15 seconds to generate
> > > *** one interrupt.
> > >
> > > *** Initially you need 550 interrupts before you turn off the LED.
> > > *** There after, you need 65536 interrupts for that to happen again.
> > >
> > > *** So you need to watch the LED for weeks and then find out that
> > > *** you do not have an ACLK.
> > >
> > > >
> > > > > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
> > > >
> > > > Forgot to change the comment. The comment should be "turn Off
> > > > LED" instead of toggle LED.
> > >
> > > *** Ok, but how did you turn on the LED? The P1 ISR toggles it.
> > > *** How do you know if it will turn on or off?
> > > >
> > > > I need the desired output, please provide suggestions to program. Thank you in advance.
> > > >
> > > >
> > > > --- In m..., "old_cow_yellow" wrote:
> > > > >
> > > > > It seems to me that there is a problem in "meeting of the minds". One mind wants some desired output. Another one wrote the code. Yet another one wrote the comments of the code.
> > > > > _________
> > > > >
> > > > > To the one who wants some desired output.
> > > > >
> > > > > You hired the wrong guys to do the job.
> > > > > _________
> > > > >
> > > > > To the one who wrote the code.
> > > > >
> > > > > Why do you set the DCO to generate 16MHz? For what reason?
> > > > >
> > > > > What is the frequency of ACLK? For that matter, does ACLK exist?
> > > > >
> > > > > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> > > > > _________
> > > > >
> > > > > And, to the one who wrote the comments.
> > > > >
> > > > > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
> > > > >
> > > > > You also need to know a little about the hardware. For example, if there is an ACLK at 32768Hz, TimerA will count at the rate of 4096 c/s. It will take not just 10 ms, but almost 5 seconds to count 20000. That means it will take about 3 quarters of an hour to do your first "using XOR toggles the pin value". There after, it will take about 88 hours to repeat that again.
> > > > >
> > > > > --- In m..., "shskurkra" wrote:
> > > > > >
> > > > > > Hi Waldemar,
> > > > > >
> > > > > > Thank you for responding to my post.
> > > > > >
> > > > > > The desired output is, MSP is in low power mode 3, Active clock (ACLK) and ACLK is divided by 8 by the Internal Divider to get the timer interrupt for software delay greater than 16-bit. Also using a tactile switch to turn LED "On" and turn LED "Off".
> > > > > >
> > > > > > First, MSP430 is in LPM3, waiting for switch to be pressed to turn LED "On". Once, switch is pressed and LED turns "On", simultaneously triggers timer to start counting in Up mode up-to TACCR0 value by comparing to CCIS (that is GND). Once LED is turned "On" program returns to LPM3 and waits for next interrupt to turn LED "Off".
> > > > > >
> > > > > > The next part is interesting because program will continuously waits either for "switch interrupt" and "timer interrupt" to turn back LED "Off". If switch is pressed before timer interrupt, makes LED to turn "Off" or if switch is not pressed before timer interrupt, makes LED to turn "Off". I did not use "if" or "while" loop to turn LED "Off" because LPM3 waits for interrupt to turn back LED "Off".
> > > > > >
> > > > > > After turning LED "Off", MSP430 goes to LPM3 waiting for switch interrupt to turn LED "On" and timer is reset. Please help me to obtain the output.
> > > > > >
> > > > > > Thank you in advance.
> > > > > >
> > > > > >
> > > > > > I looked to TI application notes for switch interrupt
> > > > > > --- In m..., "Waldemar Krzok" wrote:
> > > > > > >
> > > > > > > > Working on a LED to switch On and Off for two interrupt. First for switch,
> > > > > > > > second for timer interrupt. Tried to figure out the error, but could
> > > > > > > > figure. The code does not produce the desired output. Can anyone help me.
> > > > > > > > Here is the code. Thank you.
> > > > > > >
> > > > > > >
> > > > > > > For this it would be nice to know what is the desired output. More, it is
> > > > > > > essential to figure out what's wrong with the programme.
> > > > > > >
> > > > > > > Waldemar
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >

Then I have to use extrnal crystal for accurate timing in LPM3.

--- In m..., hans wrote:
>
> From you previous message I understand you are using the VLO as ACLK.
> The VLO is a simple RC oscillator and is absolutely not reliable
> timing-wise. Connect a real crystal to the XIN/XOUT of your controller
> to get more accurate timing. A watch crystal of 32768Hz would be a good
> option here. Don't forget to configure the required port registers to
> enable the crystal.
> You cannot use SMCLK in LPM3, but ACLK remains active.
>
> Hans
> On Tue, 22 Jun 2010 05:12:35 -0000
> "shskurkra" wrote:
>
> > Thanks OCY program is working, but without accurate timing.
> >
> > I tried with ACLK, the timer is not accurate. Error is +2 to +4 seconds from required time. Can I use SMCLK instead of ACLK, while is LPM3? From my understanding, SMCLK is disabled in LPM3.
> >
> > Thank you.
> >
> > --- In m..., "shskurkra" wrote:
> > >
> > > > *** To generate interrupt, all you need is CCIE. The other bits
> > > > *** do nothing in your situation.
> > >
> > > I require other bits like SIS, OUTMOD..etc for PWM, duty cycle. Thanks for mentioning. It is helpful to know.
> > >
> > > > *** If you use VLO as ACLK, it will take 15 seconds to generate
> > > > *** one interrupt.
> > > >
> > > > *** Initially you need 550 interrupts before you turn off the LED.
> > > > *** There after, you need 65536 interrupts for that to happen again.
> > > >
> > > > *** So you need to watch the LED for weeks and then find out that
> > > > *** you do not have an ACLK.
> > >
> > > Using VLO as ACLK, one interrupt take 15 seconds, because TACCR0 = 19999; Then, counter value should be replaced by 1 instead of 550.
> > >
> > > > *** Ok, but how did you turn on the LED? The P1 ISR toggles it.
> > >
> > > ACLK should start (generate interrupt) only if LED is turn ON from switch (connected to P1.4).
> > >
> > > > *** How do you know if it will turn on or off?
> > >
> > > For this, I need to monitor P1.4. I think "if loop" will take care of monitoring P1.4 and Timer interrupt to turn switch "Off". I did not insert a loop in my previous program because I was generating two interrupt simultaneously. Hardware interrupt has higher priority over software interrupt.
> > >
> > > OCY, I will try the above and post the outcome. Thank you for your comments. It as helpful.
> > >
> > >
> > > --- In m..., "old_cow_yellow" wrote:
> > > >
> > > >
> > > >
> > > > --- In m..., "shskurkra" wrote:
> > > > >
> > > > > Thanks OCY.
> > > > >
> > > > > > Why do you set the DCO to generate 16MHz? For what reason?
> > > > >
> > > > > In LPM3 SMCLK and DCO are disabled. DCO should not be used in this program. Thanks OCY for pointing the extra code's in program.
> > > > >
> > > > > > What is the frequency of ACLK? For that matter, does ACLK exist?
> > > > >
> > > > > I'm using eZ430-F2013. ACLK need to be sourced from VLO which is typically 4 to 20 KHz (varies from chip to chip). ACLK can be assigned from VLO by "BCSCTL3 |= LFXT1S_2;" code.
> > > >
> > > > *** But you did not do that, thus currently you have no ACLK.
> > > > *** TimerA has nothing to count
> > > >
> > > > > From MSP430 basics textbook, ACLK can be accessed by-->
> > > > > BCSCTL3 |= LFXT1S_2; //ACLK = VLO
> > > > > P2SEL = 0x00;
> > > > > P2DIR = 0x00;
> > > > > P2REN = BIT6 | BIT7; <--
> > > > >
> > > > > > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> > > > >
> > > > > TACCTL0 = CCIE = 1; //Capture/Compare timer interrupt is enabled
> > > > > CCIS = 2 ; //Select Input for TACCR0, GND is the input signal
> > > > > SCS = 1; //To Synchronous the capture with timer clcok
> > > > > OUTMOD=1 //Compare output mode is set to discharge LED by
> > > > > generating interrupt
> > > > >
> > > > > To generate interrupt after counting until the value stored
> > > > > in TACCR0.
> > > > > I need to change CCIS = 3; because Vcc will be my input for
> > > > > TACCR0 and counts until 19999. Once the value is reached,
> > > > > TACCTL0 generates a interrupt to turn LED "Off". VLO runs at
> > > > > 4KHz, TACCTLO take 5 seconds to generate the interrupt (for
> > > > > turning "Off" LED)
> > > >
> > > > *** To generate interrupt, all you need is CCIE. The other bits
> > > > *** do nothing in your situation.
> > > >
> > > > *** If you use VLO as ACLK, it will take 15 seconds to generate
> > > > *** one interrupt.
> > > >
> > > > *** Initially you need 550 interrupts before you turn off the LED.
> > > > *** There after, you need 65536 interrupts for that to happen again.
> > > >
> > > > *** So you need to watch the LED for weeks and then find out that
> > > > *** you do not have an ACLK.
> > > >
> > > > >
> > > > > > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
> > > > >
> > > > > Forgot to change the comment. The comment should be "turn Off
> > > > > LED" instead of toggle LED.
> > > >
> > > > *** Ok, but how did you turn on the LED? The P1 ISR toggles it.
> > > > *** How do you know if it will turn on or off?
> > > > >
> > > > > I need the desired output, please provide suggestions to program. Thank you in advance.
> > > > >
> > > > >
> > > > > --- In m..., "old_cow_yellow" wrote:
> > > > > >
> > > > > > It seems to me that there is a problem in "meeting of the minds". One mind wants some desired output. Another one wrote the code. Yet another one wrote the comments of the code.
> > > > > > _________
> > > > > >
> > > > > > To the one who wants some desired output.
> > > > > >
> > > > > > You hired the wrong guys to do the job.
> > > > > > _________
> > > > > >
> > > > > > To the one who wrote the code.
> > > > > >
> > > > > > Why do you set the DCO to generate 16MHz? For what reason?
> > > > > >
> > > > > > What is the frequency of ACLK? For that matter, does ACLK exist?
> > > > > >
> > > > > > In TACCTL0, aside from CCIE=1, why do you set CCIS=2, SCS=1, and OUTMOD=1? For what reason?
> > > > > > _________
> > > > > >
> > > > > > And, to the one who wrote the comments.
> > > > > >
> > > > > > You need to know at least a little about c. For example &= has nothing to do with XOR and will not toggle anything.
> > > > > >
> > > > > > You also need to know a little about the hardware. For example, if there is an ACLK at 32768Hz, TimerA will count at the rate of 4096 c/s. It will take not just 10 ms, but almost 5 seconds to count 20000. That means it will take about 3 quarters of an hour to do your first "using XOR toggles the pin value". There after, it will take about 88 hours to repeat that again.
> > > > > >
> > > > > > --- In m..., "shskurkra" wrote:
> > > > > > >
> > > > > > > Hi Waldemar,
> > > > > > >
> > > > > > > Thank you for responding to my post.
> > > > > > >
> > > > > > > The desired output is, MSP is in low power mode 3, Active clock (ACLK) and ACLK is divided by 8 by the Internal Divider to get the timer interrupt for software delay greater than 16-bit. Also using a tactile switch to turn LED "On" and turn LED "Off".
> > > > > > >
> > > > > > > First, MSP430 is in LPM3, waiting for switch to be pressed to turn LED "On". Once, switch is pressed and LED turns "On", simultaneously triggers timer to start counting in Up mode up-to TACCR0 value by comparing to CCIS (that is GND). Once LED is turned "On" program returns to LPM3 and waits for next interrupt to turn LED "Off".
> > > > > > >
> > > > > > > The next part is interesting because program will continuously waits either for "switch interrupt" and "timer interrupt" to turn back LED "Off". If switch is pressed before timer interrupt, makes LED to turn "Off" or if switch is not pressed before timer interrupt, makes LED to turn "Off". I did not use "if" or "while" loop to turn LED "Off" because LPM3 waits for interrupt to turn back LED "Off".
> > > > > > >
> > > > > > > After turning LED "Off", MSP430 goes to LPM3 waiting for switch interrupt to turn LED "On" and timer is reset. Please help me to obtain the output.
> > > > > > >
> > > > > > > Thank you in advance.
> > > > > > >
> > > > > > >
> > > > > > > I looked to TI application notes for switch interrupt
> > > > > > > --- In m..., "Waldemar Krzok" wrote:
> > > > > > > >
> > > > > > > > > Working on a LED to switch On and Off for two interrupt. First for switch,
> > > > > > > > > second for timer interrupt. Tried to figure out the error, but could
> > > > > > > > > figure. The code does not produce the desired output. Can anyone help me.
> > > > > > > > > Here is the code. Thank you.
> > > > > > > >
> > > > > > > >
> > > > > > > > For this it would be nice to know what is the desired output. More, it is
> > > > > > > > essential to figure out what's wrong with the programme.
> > > > > > > >
> > > > > > > > Waldemar
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>