CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC24F - watchdog fail on SLEEP-IDLE-Mode

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andresteff



Joined: 21 Mar 2020
Posts: 44

View user's profile Send private message

PIC24F - watchdog fail on SLEEP-IDLE-Mode
PostPosted: Tue May 11, 2021 11:09 am     Reply with quote

I want to use the IDLE-Mode in sleep. The time-out of the wdt is 256ms.
The problem:
If the timer5 interrupt is enabled the wdt works wrong in sleep-idle, but correct in sleep-full!

If the timer5 interrupt is disabled the wdt works correct in sleep-idle and correct in sleep-full! All ok!
I tested also timer4 and timer3, they have same behavior.

What's wrong?

CCS Version: 5.080 with IDE
PIC: PIC24F16KA301
ICD3

This a complete test program.
The wdt works wrong. I measure 8,3kHz on the toggle led for test.
When timer5 interrupt is disabled, the code works correct.
Code:

#include <24F16KA301.h>

#device ADC=8       
#device ICSP=3


#use delay(internal=500000)

#fuses LPRC                   //Internal low power RC Oscillator
#fuses LPFRC_DIV              //Low-Power FRC oscillator with divide-by-N
#fuses LPRCLOW                //Low-Power FRC Low Power and Low Accuracy
//#fuses CKSFSM                 //Clock Switching is enabled, fail Safe clock monitor is enabled
#fuses CKSNOFSM               //Clock Switching is enabled, fail Safe clock monitor is disabled


#fuses OSCIO                  //OSC2 is general purpose output

#fuses WDT_SW                    //No Watch Dog Timer, enabled in Software
//#fuses WDT                  //Watch Dog Timer

#FUSES NOBROWNOUT                //No brownout reset
#fuses MCLR                      //Master Clear pin enabled
#fuses PUT                       //Power Up Timer
#fuses SOSC_DIGITAL              //SOSC pins set for Digital mode for use with external clock or Digital I/O. Um RA4 und RB4 als dig out zu nutzen.



#define LED_gr     PIN_B4


#INT_TIMER5   

void TIM5_Int(void)


}


void main()
{
         
            setup_oscillator( OSC_LPFRC , 500000);
            #use delay(clock=500000)
            delay_ms(10);
           
            output_low ( PIN_A3);
         
            setup_timer5( TMR_INTERNAL | TMR_DIV_BY_8 );
            set_timer5(49911);
           
            enable_interrupts(INT_TIMER5);
            disable_interrupts(GLOBAL);
         
            Setup_wdt(WDT_256MS);   
           
            while(1)
            {
            sleep(SLEEP_IDLE);      // with  sleep(SLEEP_FULL); , it works
            output_toggle(LED_gr);
            }
 
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed May 12, 2021 12:22 am     Reply with quote

It's working right.....

In the idle modes, the timers keep running. If the interrupt triggers (if
enabled), this wakes the chip up. So it'll execute the timer code, toggle the
pin and go back to sleep. The act of entering sleep mode resets the
watchdog. So the watchdog will never trigger.

Remember on the PIC24's, you can put a 'limit' value for the timer count
as an extra value after the clock source etc., in the timer setup. So you can
program the timer to tick at an exact interval (within the accuracies of
the clock source). If you want it to keep ticking, choose a value that suits,
and then have a counter updated in the tick, and only toggle the pin
when this gets to the total time you want.
andresteff



Joined: 21 Mar 2020
Posts: 44

View user's profile Send private message

PostPosted: Mon May 17, 2021 3:18 am     Reply with quote

Ok, thanks for the info. They "opened my eyes".

My "mistake" was the GLOBAL interrupt was disabled. And the timer interrupt enabled. When by an timer overflow the flag is set, the chip goes out of the idle mode - set the led - goes in idle, and then immediately out of the idle,
because the interrupt flag of the timer is always still set!
Therefore the frequency of 8,3kHz!

If the GLOBAL interrupt is enabled, the chip goes in the ISR, and the interrupt flag of the timer is cleared.

The chip stay until the next timer overflow in idle-mode.
andresteff



Joined: 21 Mar 2020
Posts: 44

View user's profile Send private message

PostPosted: Mon May 17, 2021 3:20 am     Reply with quote

A nice feature of the PIC24 is still, that the peripheral can enabled/disabled in Idle-Mode.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group