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 CCS Technical Support

[SOLVED] Very Simple Question ! Watchdog

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



Joined: 16 Aug 2019
Posts: 52

View user's profile Send private message

[SOLVED] Very Simple Question ! Watchdog
PostPosted: Wed Nov 13, 2019 12:49 am     Reply with quote

Hello,

It will be a very basic question I know but when you don't know the answer it is hard for you. I want to use watchdog and I set it to 1ms. I wanted to simulate in a very basic way. I used my main while loop and I wanted to see my restart. But it doesn't restart itself acordingly to the time. It is restarting itself maybe 5 mins or 10 mins later. I don't know why. I searched everywhere including this forum but I couldn't find any solution. Maybe I couldn't understand solutions because of my english. Here is my code:

Code:
#include <./33EP64MC204.h>

#DEVICE NESTED_INTERRUPTS=TRUE
#device PASS_STRINGS=IN_RAM
#FUSES WDT
#FUSES NOJTAG                   //JTAG disabled
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES FRC                      //internal oscillator icin gerekli
#FUSES OSCIO                    //OSC2 is general purpose output

#use delay(internal=80MHz)     
#use i2c(master,I2C1,FAST)

#use spi(MASTER, SPI1, MODE=0, BITS=16,CLOCK_HIGH=3,CLOCK_LOW=3,FORCE_HW,STREAM=SSP1)

#pin_select U1TX=PIN_B9
#pin_select U1RX=PIN_C6
#use rs232(UART1, baud=115200,parity=N,stop=1, ERRORS, stream=GSM)
#pin_select U2TX=PIN_B11 //UART RFID PINS
#pin_select U2RX=PIN_B5
#use rs232(UART2, baud=9600,parity=N,stop=1, ERRORS, stream=RFID)
#use rs232(baud=9600,parity=N,stop=1,xmit=PIN_B6 ,rcv=PIN_B7,enable =PIN_B8, stream = RS485) //SOFTWARE RS485

void main() {
    setup_oscillator(OSC_INTERNAL, 80000000);
   fprintf(RS485, "starting");
   setup_wdt(WDT_1MS);
 while (1) {
   
        output_toggle(PIN_A2);
        delay_ms(10000);
    }
}


Last edited by camleot23 on Thu Nov 14, 2019 12:21 am; edited 2 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 1:00 am     Reply with quote

WHAT CHIP?.

You carefully leave the chip line out of the posted code.....
camleot23



Joined: 16 Aug 2019
Posts: 52

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 1:03 am     Reply with quote

My bad, I'm sorry. dsPIC33EP64MC204, MPLAB v5.25 CCS C compiler v5.016
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 4:01 am     Reply with quote

Quote:
setup_wdt(WDT_1MS);

Why use 1 ms for your test ? I would have picked a longer time, such
as 4 seconds. Make it long enough to fit human ability to notice the delay
time.
camleot23



Joined: 16 Aug 2019
Posts: 52

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 4:40 am     Reply with quote

In anyway, am I not supposed to see this line on my terminal?

fprintf(RS485, "starting");
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 5:49 am     Reply with quote

A couple of things wrong with what you post, but then a question:

You should use:
Code:

#include <./33EP64MC204.h>

#DEVICE NESTED_INTERRUPTS=TRUE
#device PASS_STRINGS=IN_RAM
#FUSES WINDIS
#FUSES NOWDT
#FUSES NOJTAG                   //JTAG disabled
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES FRC                      //internal oscillator icin gerekli
#FUSES OSCIO                    //OSC2 is general purpose output

#use delay(internal=80MHz)     
#use i2c(master,I2C1,FAST)

#use spi(MASTER, SPI1, MODE=0, BITS=16,CLOCK_HIGH=3,CLOCK_LOW=3,FORCE_HW,STREAM=SSP1)

#pin_select U1TX=PIN_B9
#pin_select U1RX=PIN_C6
#use rs232(UART1, baud=115200,parity=N,stop=1, ERRORS, stream=GSM)
#pin_select U2TX=PIN_B11 //UART RFID PINS
#pin_select U2RX=PIN_B5
#use rs232(UART2, baud=9600,parity=N,stop=1, ERRORS, stream=RFID)
#use rs232(baud=9600,parity=N,stop=1,xmit=PIN_B6 ,rcv=PIN_B7,enable =PIN_B8, stream = RS485) //SOFTWARE RS485

void main() {
   setup_oscillator(OSC_INTERNAL, 80000000);
   fprintf(RS485, "starting");
   setup_wdt(WDT_ON|WDT_1MS); //enable the watchdog
 while (1) {
   
        output_toggle(PIN_A2);
        delay_ms(10000);
    }
}   


Two big differences. The watchdog is off in the fuses. Otherwise it is on
at the start of the code. WINDIS needs to be set or when you use the
watchdog, it can only be reset in an precise 'window' of it's cycle.

Now the question. You use the word 'simulate'. You do realise that the
simulator in MPLAB-X will not simulate a watchdog?. If you are trying
this in the simulator, then this is why it is not working....
It's 'odd' in this. They say that the WDT is one of the simulated
peripherals, but when you build in any DEBUG mode (including the
simulator), they disable the watchdog (this since most hardware
debuggers don't support the watchdog).
So debugging or simulation, the watchdog won't normally work.

Then on your compiler version, I am not seeing the setup_wdt
actually writing the bits to the configuration register in RAM. So you will
probably have to set these in the fuses to work. Or write the word
yourself. Without this it'll default to the maximum that is possible.
128 seconds. Sounds suspiciously like what you are seeing....
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 6:20 am     Reply with quote

I don't use that PIC, but historically WDT are NOT accurate. They usually are driven from an internal RC oscillator,so maybe +-1-5% clock, then there's temperature affects and perhaps VDD.
It's super important to read the 400-700 pages of your PIC's dataheet and see what the WDT specs really are.
My 'gut' says you won't get 1.00000ms from the WDT.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 6:55 am     Reply with quote

No, the WDT on this is specified to give between 0.8, and 1.2mSec for the
'nominal' 1mSec setting.
camleot23



Joined: 16 Aug 2019
Posts: 52

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 7:33 am     Reply with quote

First thank you for your replies. Second, again I'm sorry for the 'simulate' word. Because I wanted to mean 'try' by simulate on my hardware. I was uploading the code into my hardware and running it and observing it. Third, I added these;

#FUSES WINDIS
#FUSES NOWDT

setup_wdt(WDT_ON|WDT_1MS);

but again, no work.
Quote:
I am not seeing the setup_wdt
actually writing the bits to the configuration register in RAM. So you will
probably have to set these in the fuses to work.

Can I find how to set these bits on this forum or in datasheet ?
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 9:24 am     Reply with quote

The PIC processor 'header' file( the first line of code...) will have a list of available registers and bit settings.
The datasheet will explain them all BUT be in Microchip words not necessarily what CCS calls them. MOst are very similar if not the same words though.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Wed Nov 13, 2019 1:48 pm     Reply with quote

For your 1mSec,

#FUSES WPOSTS1
#FUSES WPRES32

Be aware that a watchdog running at this sort of rate is 'silly', and almost
certainly pointless.
The correct way to use a watchdog, is to decide the time criteria
that is needed for reliable operation, and set the watchdog at just under
this. Then have the code verify that everything is working before resetting
the watchdog, preferably in just one location. The watchdog on the flight
control computer on the shuttle used just under 0.5seconds, and this was
considered to be as fast as it was possible to go and still be properly
testing that all systems were functioning correctly.
camleot23



Joined: 16 Aug 2019
Posts: 52

View user's profile Send private message

PostPosted: Thu Nov 14, 2019 12:21 am     Reply with quote

I understand. That solved my problem. Thank you both.

Have a nice day
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