EmbeddedRelated.com
Forums

Re: Question about Watchdog as interval timer

Started by bb_stefan December 17, 2007
I don't really know, what your goal is... ?

But try this:
Reset the WDT-Interrupt Flag in main():
...
IFG1 &=~WDTIFG; <--- added !
IE1 &=~WDTIE;
WDTCTL = WDTPW + WDTHOLD;
WDTCTL = WDT_ADLY_1000;
IE1 |= WDTIE;
...
Since it seems, that if you do a reset inside the WDT-ISR, the WDTIFG
will not be reset the right way, even though you do reset it in your
ISR. I don't know why... maybe a bug ???

By the way, to do a software reset you can simply do:
WDTCTL = 0;
in your ISR!
Any acces to WDTCTL without password (WDTPW) will generate a PUC.

--- In m..., "cmaybisher" wrote:
> this is the main code:
>
> void main(void)
> {
> unsigned int temp,CCstate; // Temp int for
> RF core state machine
> int i;
> unsigned int Status;
>
> IE1 &=~WDTIE;
> WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> WDTCTL = WDT_ADLY_1000; //configures the timer interval
> IE1 |= WDTIE;
>
> Status =WDTCTL;
> WDTCTL = (Status & 0x00FF) + WDTPW + WDTCNTCL;
>
> CheckBSL(); //here configures only the ports
>
> _BIS_SR(GIE); // Enable Interrupts
>
>
> while(1)
> {
> CPU_State =1;
> }
> This is the interrupt:
>
> //==============================================> //==== Timer interval Watchdog service routine
> //==============================================> #pragma vector=WDT_VECTOR
> __interrupt void watchdog_timer (void)
> {
> // _BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits
> from 0(SR)
> // machine_flags.bits.exit_sleep_handler = 1;
> // P4OUT ^= BIT5;
> IFG1 &=~WDTIFG;
>
> P4OUT ^= BIT5;
>
> if(CPU_State ==0)
> {
> _BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0
> (SR)
> asm("NOP");
> }
> else
> {
> asm("JMP _reset_vector");
> WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> WDTCTL =~WDTPW; //arrived from bug then
> } //reset the processor.
> }
>
> --- In m..., "bb_stefan" wrote:
> >
> > A little piece of your code would help very much to help you!
> >
> >
> > --- In m..., "cmaybisher" wrote:
> > >
> > > Hi,
> > > I used the watchdog as interval timer. In its interrupt, I write
> a
> > > different number of the password to cause reset. My problem is
> that I
> > > configured the watchdog for interrupting every second and I saw
> after
> > > the first reset that second reset occurred after some
> miliseconds.
> > > Please, could somebody help me?
> > >
> > > Thanks in advance.
> > >
> > > Claudio
> > >
>

Beginning Microcontrollers with the MSP430

Thanks a lot Stefan!!!!

I'm using the sleep mode in LMP3 and the only clock source is this
mode that remains working is ACLK, then I use the watchdog interval
timer for waking up the processor. (I suppose that my idea is right)
In other way, I need a watchdog in the system, therefore, this is
the reason I wrote the question sentence inside the interrupt.
Before going to sleep I clear the variable CPU_State, If the
processor didn't receive interrupt from sleep mode, this variable
will be set.

--- In m..., "bb_stefan" wrote:
>
> I don't really know, what your goal is... ?
>
> But try this:
> Reset the WDT-Interrupt Flag in main():
> ...
> IFG1 &=~WDTIFG; <--- added !
> IE1 &=~WDTIE;
> WDTCTL = WDTPW + WDTHOLD;
> WDTCTL = WDT_ADLY_1000;
> IE1 |= WDTIE;
> ...
> Since it seems, that if you do a reset inside the WDT-ISR, the
WDTIFG
> will not be reset the right way, even though you do reset it in
your
> ISR. I don't know why... maybe a bug ???
>
> By the way, to do a software reset you can simply do:
> WDTCTL = 0;
> in your ISR!
> Any acces to WDTCTL without password (WDTPW) will generate a PUC.
>
> --- In m..., "cmaybisher" wrote:
> >
> >
> > this is the main code:
> >
> > void main(void)
> > {
> > unsigned int temp,CCstate; // Temp int
for
> > RF core state machine
> > int i;
> > unsigned int Status;
> >
> > IE1 &=~WDTIE;
> > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> > WDTCTL = WDT_ADLY_1000; //configures the timer
interval
> > IE1 |= WDTIE;
> >
> > Status =WDTCTL;
> > WDTCTL = (Status & 0x00FF) + WDTPW + WDTCNTCL;
> >
> > CheckBSL(); //here configures only the ports
> >
> > _BIS_SR(GIE); // Enable Interrupts
> >
> >
> > while(1)
> > {
> > CPU_State =1;
> > }
> >
> >
> > This is the interrupt:
> >
> > //==============================================> > //==== Timer interval Watchdog service routine
> > //==============================================> > #pragma vector=WDT_VECTOR
> > __interrupt void watchdog_timer (void)
> > {
> > // _BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits
> > from 0(SR)
> > // machine_flags.bits.exit_sleep_handler = 1;
> > // P4OUT ^= BIT5;
> > IFG1 &=~WDTIFG;
> >
> > P4OUT ^= BIT5;
> >
> > if(CPU_State ==0)
> > {
> > _BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits
from 0
> > (SR)
> > asm("NOP");
> > }
> > else
> > {
> > asm("JMP _reset_vector");
> > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> > WDTCTL =~WDTPW; //arrived from bug
then
> > } //reset the processor.
> > }
> >
> > --- In m..., "bb_stefan" wrote:
> > >
> > > A little piece of your code would help very much to help you!
> > >
> > >
> > > --- In m..., "cmaybisher"
wrote:
> > > >
> > > > Hi,
> > > > I used the watchdog as interval timer. In its interrupt, I
write
> > a
> > > > different number of the password to cause reset. My problem
is
> > that I
> > > > configured the watchdog for interrupting every second and I
saw
> > after
> > > > the first reset that second reset occurred after some
> > miliseconds.
> > > > Please, could somebody help me?
> > > >
> > > > Thanks in advance.
> > > >
> > > > Claudio
> > > >
> > >
>
> I'm using the sleep mode in LMP3 and the only clock source is this
> mode that remains working is ACLK, then I use the watchdog interval
> timer for waking up the processor. (I suppose that my idea is right)

Yes it is!
> In other way, I need a watchdog in the system, therefore, this is
> the reason I wrote the question sentence inside the interrupt.
> Before going to sleep I clear the variable CPU_State, If the
> processor didn't receive interrupt from sleep mode, this variable
> will be set.

what other source could the WDT cause to interrupt ???
In sleep mode the only source is the WDT interval timer (clocked by
ACLK). If ACLK fails, you will never get an interrupt any more!
On the other hand, if you wake up, keep awake and do some stuff, then
you will also receive an WDT interrupt after 1sec. If this is what you
are looking for, then you made a programming mistake. Your code during
wake-up must not exeed 1sec of duration!

Did the hint with
Reset the WDT-Interrupt Flag in main():
...
IFG1 &=~WDTIFG; <--- added !
...
solve your problem?
Thanks again, your sentence gave me the solution.

Claudio.

--- In m..., "bb_stefan" wrote:
>
> > I'm using the sleep mode in LMP3 and the only clock source is
this
> > mode that remains working is ACLK, then I use the watchdog
interval
> > timer for waking up the processor. (I suppose that my idea is
right)
>
> Yes it is!
> > In other way, I need a watchdog in the system, therefore, this
is
> > the reason I wrote the question sentence inside the interrupt.
> > Before going to sleep I clear the variable CPU_State, If the
> > processor didn't receive interrupt from sleep mode, this
variable
> > will be set.
>
> what other source could the WDT cause to interrupt ???
> In sleep mode the only source is the WDT interval timer (clocked by
> ACLK). If ACLK fails, you will never get an interrupt any more!
> On the other hand, if you wake up, keep awake and do some stuff,
then
> you will also receive an WDT interrupt after 1sec. If this is what
you
> are looking for, then you made a programming mistake. Your code
during
> wake-up must not exeed 1sec of duration!
>
> Did the hint with
> Reset the WDT-Interrupt Flag in main():
> ...
> IFG1 &=~WDTIFG; <--- added !
> ...
> solve your problem?
>