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

#use_delay bug?

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



Joined: 14 Nov 2012
Posts: 5

View user's profile Send private message

#use_delay bug?
PostPosted: Tue Jun 28, 2016 6:11 pm     Reply with quote

The following sample code to illustrate the problem seems to increase the loop cycle by exactly the delay_ms value (ie changing to 50ms causes a 50ms increase in total loop time. I think this is a bug, because the delay_ms shouldn't be resetting the WDT unless #use_delay has the restart_wdt option included.

Is there a way, not documented in the manual or that I've missed, to prevent the delay routines from resetting the wdt?

Compiler version 5.061 (and at least back a few versions)

Code:

#include <12LF1840.h>               

#device adc=10
#FUSES WDT                    //Watch Dog Timer
#FUSES PUT                      //Power Up Timer
#FUSES BROWNOUT               //brownout reset
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOLVP                    //No low voltage
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NODEBUG

#include <stdio.h>
#include <stdlib.h>

#use delay(internal=16MHZ)

void main() {
    setup_wdt(WDT_256ms);           
    While(1) {
        output_low(PIN_A5);
        delay_ms(10);
        output_high(PIN_A5);
        sleep();
    }
}


Thanks in advance to anybody that can confirm.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 28, 2016 7:16 pm     Reply with quote

Look at the .LST file. If the compiler is doing what you say, you'll find
CLRWDT instructions in the ASM code for #use delay().

I'd suggest getting rid of these two lines since they are not used in your
program and they clutter up the .LST file:
Code:
#include <stdio.h>
#include <stdlib.h>
bartman



Joined: 14 Nov 2012
Posts: 5

View user's profile Send private message

PostPosted: Tue Jun 28, 2016 8:42 pm     Reply with quote

When in doubt, read f'n manual...turns out on this particular chip, the sleep command clears the WDT before going to sleep, and again coming out.

Thanks anyway Laughing
Ttelmah



Joined: 11 Mar 2010
Posts: 19408

View user's profile Send private message

PostPosted: Wed Jun 29, 2016 12:52 am     Reply with quote

All PIC's do this (can't think of any that doesn't)....
bartman



Joined: 14 Nov 2012
Posts: 5

View user's profile Send private message

PostPosted: Wed Jun 29, 2016 1:17 am     Reply with quote

Your right they do Embarassed . Its not something I'd ever really considered or cared about until I wanted a semi accurate timer that works in sleep in a low power application, as per an old mchip appnote.

Thanks guys for setting me straight Cool
jeremiah



Joined: 20 Jul 2010
Posts: 1332

View user's profile Send private message

PostPosted: Wed Jun 29, 2016 8:17 am     Reply with quote

bartman wrote:
Your right they do Embarassed . Its not something I'd ever really considered or cared about until I wanted a semi accurate timer that works in sleep in a low power application, as per an old mchip appnote.

Thanks guys for setting me straight Cool


There are quite a few chips out there that can do that with an external timer clock/crystal on timer1 (or timer0). You have to check the data sheet to make sure the time used has an asynchronous mode and that you can wake from sleep using that input.

I don't work with many of the 8bit chips, but as an example on almost any of the PIC24FJ chips you can put an accurate 32kHz crystal on the SOSC pins and tell timer 1 to run off of that. The PIC24FJ series will wake from sleep off of this interrupt. I've used various flavors of PIC24FJyyGAxxx chips in this configuration

Additionally if you don't care about accuracy much at all some small number of chips have an internal LPRC crystal that can be assigned to timers to wake from sleep. However, the majority (all?) of these have really abysmal tolerances (upwards of + or - 15%). The PIC24F32KA302/304 has this option as an example. However, I usually fall back on the above suggestion of external 32kHz crystal as I want more accurate timing.

Also, this thread from the Code Library might be of interest if you come up with a good hardware implementation:
https://www.ccsinfo.com/forum/viewtopic.php?t=26177
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Jun 29, 2016 2:05 pm     Reply with quote

without knowing your counting needs - i've found
the DS1305 is an awfully nice way to get larger timing increments
and useful alarms with very low pic overhead.
especially good for waking from sleep with a single pin interrupt flag after n-seconds or more of activation.

The best part is - a simple driver lets you deal in whole -second multiples of alarm with an external interrupt ( wake ) from the chip...

if you need resolution to "wake" that is sub-second - that's tougher.


Last edited by asmboy on Wed Jun 29, 2016 3:32 pm; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19408

View user's profile Send private message

PostPosted: Wed Jun 29, 2016 2:23 pm     Reply with quote

In fact just about all the PIC's (except a few PIC12's etc.), can wake using a timer1 crystal. You setup the timer to stay running, and then just load a 'preload' value into the timer counter, disable global interrupts, clear and then enable the timer interrupt, and sleep. When the timer wraps, the interrupt triggers and wakes the chip. You then disable the timer interrupt and do what you want. Since the global interrupt is disabled, no handler is called.
So with a 32768Hz crystal, a 'preload' of 49152, gives a wake in half a second from when loaded. Many times more accurate than any of the watchdogs.
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