Watchdoc timer connecting and setting prescaler
Moderator: Benj
Watchdoc timer connecting and setting prescaler
I have read as much as possible the topics on watchdog timer. But I do not find explanation on how to make longer watchdog time's (e.g. approx. 1 second instead of 18 msec).
What I am looking for is:
- which c-code to add in the start of a Flowcode program to 'connect' the prescaler to the watchdog timer, and
- which c-code to add there also a prescaling number, e.g. 56 (to get approximately a 1 second watchdog timespan).
I hope someone can help me in this.
Note: at the moment in the start of the Flowcode program we added e.g. the c-code " osccon = 0x60; " to use a 4 MHz oscillator (but we want to go to 32 kHz to minimize current consumption).
What I am looking for is:
- which c-code to add in the start of a Flowcode program to 'connect' the prescaler to the watchdog timer, and
- which c-code to add there also a prescaling number, e.g. 56 (to get approximately a 1 second watchdog timespan).
I hope someone can help me in this.
Note: at the moment in the start of the Flowcode program we added e.g. the c-code " osccon = 0x60; " to use a 4 MHz oscillator (but we want to go to 32 kHz to minimize current consumption).
Re: Watchdoc timer connecting and setting prescaler
I mentioned the word 'prescaler', but now I think it should be 'postscaler'. Could be simpler?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Hello,
What chip are you using and what is the clock speed? This will dictate how long you can set the watchdog timeout to last for.
What chip are you using and what is the clock speed? This will dictate how long you can set the watchdog timeout to last for.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Watchdoc timer connecting and setting prescaler
I am using a PIC12F683.
I want to use it at 32 kHz with external crystal oscillator.
I want to use it at 32 kHz with external crystal oscillator.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Hello,
Ok that's great thanks. The Watchdog prescaler is shared with the Timer 0 so you won't be able to use timer 0 in your program.
Also the timer is linked to the 31KHz internal clock and so will not be effected by your clock speed.
Here is a C code you can insert using a C code icon at the start of your program.
This should give you a watchdog window of (1 / (31000 / 128 / 256)) = 1.057 seconds
If you look at the datasheet then it describes the values you can use for the option_reg and wdtcon registers so you can work out what value to use to get the window you require.
Ok that's great thanks. The Watchdog prescaler is shared with the Timer 0 so you won't be able to use timer 0 in your program.
Also the timer is linked to the 31KHz internal clock and so will not be effected by your clock speed.
Here is a C code you can insert using a C code icon at the start of your program.
Code: Select all
option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler
wdtcon = 0b00000111; //Configure watchdog 1:256 Prescaler, Software Watchdog enabled
If you look at the datasheet then it describes the values you can use for the option_reg and wdtcon registers so you can work out what value to use to get the window you require.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Watchdoc timer connecting and setting prescaler
Thanks for your help. I think I understand it.
I want to attach an external standard 32kHz crystal oscillator signal to pin 2 (pin 3 not used). What must I add more to the program to get the 12F683 using this external clock signal?
With project build option I can already specify the 32768 frequency.
I want to attach an external standard 32kHz crystal oscillator signal to pin 2 (pin 3 not used). What must I add more to the program to get the 12F683 using this external clock signal?
With project build option I can already specify the 32768 frequency.
Re: Watchdoc timer connecting and setting prescaler
The watchdog timer is now effectively 1 second. Thanks for your help.
I learned however that this does not affect overall processing time compared to the default approx. 18 msec watchdog timer.
I learned however that this does not affect overall processing time compared to the default approx. 18 msec watchdog timer.
- amarsingh12
- Posts: 9
- Joined: Sun Jul 17, 2011 4:21 pm
- Has thanked: 1 time
- Been thanked: 3 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
I am using the same code at the begining of my program.. and it is not working.. I am also attaching the flowcode file that I am building... please assist..
option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler
wdtcon = 0b00000111; //Configure watchdog 1:256 Prescaler, Software Watchdog enabled
I am also trying to setup a 1 second WDT
Is there some thing that I am missing here.. i am just trying to make sure that the Pic reset's if the program get stuck.
option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler
wdtcon = 0b00000111; //Configure watchdog 1:256 Prescaler, Software Watchdog enabled
I am also trying to setup a 1 second WDT
Is there some thing that I am missing here.. i am just trying to make sure that the Pic reset's if the program get stuck.
- Attachments
-
- testing.fcfx
- (16.1 KiB) Downloaded 499 times
- amarsingh12
- Posts: 9
- Joined: Sun Jul 17, 2011 4:21 pm
- Has thanked: 1 time
- Been thanked: 3 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
It worked.. sorry... the clear Watch dog had to be used in every macros.. I was using it only in the main function... thanks guys for this awesome Forum
- achillis1
- Posts: 347
- Joined: Thu Oct 09, 2008 9:19 am
- Has thanked: 91 times
- Been thanked: 8 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Hello,
I have pic 16F877A and I want to set the WDT to be around 1 second. Based on the data sheet details I post below what is the longest time for WDT?
The crystal is the default one 19Mhz
By the way , why do we put 0b at the beginning of the C code? "0b00000111"
2. The option_reg register I can spot on the datasheet, what about wdtcon? What is this , is a register?
3.
Thank you,
Best Regards,
Andreas Achilleos
I have pic 16F877A and I want to set the WDT to be around 1 second. Based on the data sheet details I post below what is the longest time for WDT?
The crystal is the default one 19Mhz
By the way , why do we put 0b at the beginning of the C code? "0b00000111"
2. The option_reg register I can spot on the datasheet, what about wdtcon? What is this , is a register?
3.
What does this user mean? Is there an option I should use for WDT in flowcode?It worked.. sorry... the clear Watch dog had to be used in every macros.. I was using it only in the main function...
Thank you,
Best Regards,
Andreas Achilleos
- Attachments
-
- 16f877a.png
- (76.91 KiB) Downloaded 8466 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Hi,
Timeout will be exactly the same period if using 4MHz or 64MHz clock rate.
If you take 18ms for the normal timeout (18ms is approx as actual time depends on supply voltage, temperature etc) = (1:1), then
1:2 = 18ms*2 =36ms
So maximum
= 1:128 = 18ms*128 = 2.3 seconds
Just like 0x means the value will be in hex format e.g. 0xF8 = F8 hex.
Its used on the newer devices like 16F18xx range and is used to increase watchdog timeout even longer.
For example 256 seconds.
When you need to do to prevent this is place a C code block within strategic places.
They need to be placed before 18ms has elapsed after the previous has prevent watchdog timer from timing out.
Another thing Flowcode allows you to do is to enable Auto clear Watchdog within Build, Project options.
What Auto clear Watchdog does is automatically places a MX_CLEAR_WATCHDOG;whenever a delay or a component containing a delay is used.
For example RS232, LCD etc.
The purpose of the watchdog timer being enabled is to reset the microelectronic if a bug or interference causes the it to get stuck in a loop.
One thing that must not be does is place a clear watchdog command within an interrupt.
Martin
The watchdog time out is totally independent of clock speed.achillis1 wrote: have pic 16F877A and I want to set the WDT to be around 1 second. Based on the data sheet details I post below what is the longest time for WDT?
The crystal is the default one 19Mhz
Timeout will be exactly the same period if using 4MHz or 64MHz clock rate.
If you take 18ms for the normal timeout (18ms is approx as actual time depends on supply voltage, temperature etc) = (1:1), then
1:2 = 18ms*2 =36ms
So maximum
= 1:128 = 18ms*128 = 2.3 seconds
0b is just stating that the value is binary format.achillis1 wrote:By the way , why do we put 0b at the beginning of the C code? "0b00000111"
Just like 0x means the value will be in hex format e.g. 0xF8 = F8 hex.
Yes but not on 16F877Aachillis1 wrote:The option_reg register I can spot on the datasheet, what about wdtcon? What is this , is a register?
Its used on the newer devices like 16F18xx range and is used to increase watchdog timeout even longer.
For example 256 seconds.
If watchdog timer setting are left as a default value then hardware will start then after 18ms will keep restartingachillis1 wrote:What does this user mean? Is there an option I should use for WDT in flowcode?
When you need to do to prevent this is place a C code block with
Code: Select all
MX_CLEAR_WATCHDOG;
They need to be placed before 18ms has elapsed after the previous
Code: Select all
MX_CLEAR_WATCHDOG;
Another thing Flowcode allows you to do is to enable Auto clear Watchdog within Build, Project options.
What Auto clear Watchdog does is automatically places a MX_CLEAR_WATCHDOG;whenever a delay or a component containing a delay is used.
For example RS232, LCD etc.
The purpose of the watchdog timer being enabled is to reset the microelectronic if a bug or interference causes the it to get stuck in a loop.
One thing that must not be does is place a clear watchdog command within an interrupt.
Martin
Martin
- achillis1
- Posts: 347
- Joined: Thu Oct 09, 2008 9:19 am
- Has thanked: 91 times
- Been thanked: 8 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Hello Martin,
Always glad when you reply a post!
1. So, I will just use the option_reg only without the wdtcon.
2. In order to use the "option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler" code, it is prerequisite that I enable WDT within project options, yes?
a. If I do that in order to have 2.3 seconds of delay; then if I have a RS232 component , WDT will be disabled and routine will loop until a character is received in RS232?
Thank you,
Best Regards,
Andreas Achilleos
Always glad when you reply a post!
1. So, I will just use the option_reg only without the wdtcon.
2. In order to use the "option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler" code, it is prerequisite that I enable WDT within project options, yes?
a. If I do that in order to have 2.3 seconds of delay; then if I have a RS232 component , WDT will be disabled and routine will loop until a character is received in RS232?
Thank you,
Best Regards,
Andreas Achilleos
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Hi Andreas,
To confirm you can always set a register value e.g
You can make up the value at this stage.
Then compile and if register is not available (or misspelt) then you will just get an error.
If the count is not reset with a clear command then as soon a maximum count is reached then hardware will reboot.
The MX_CLEAR_WATCHDOG; command and using RS232 components should each reset the WatchDog Timer to prevent hardware rebooting.
Martin
Thank you, always happy to postachillis1 wrote:Always glad when you reply a post!
Yes that's correct.achillis1 wrote:1. So, I will just use the option_reg only without the wdtcon.
To confirm you can always set a register value e.g
Code: Select all
wdtcon=0b1101;
Then compile and if register is not available (or misspelt) then you will just get an error.
Yes you will need to enable within configure settings and I would recommend to enable Auto Clear Watchdog on the general tab.achillis1 wrote:In order to use the "option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler" code, it is prerequisite that I enable WDT within project options, yes?
No not true when WDT is enabled, watchdog timer is constantly counting up no matter what.achillis1 wrote:If I do that in order to have 2.3 seconds of delay; then if I have a RS232 component , WDT will be disabled and routine will loop until a character is received in RS232?
If the count is not reset with a clear command then as soon a maximum count is reached then hardware will reboot.
The MX_CLEAR_WATCHDOG; command and using RS232 components should each reset the WatchDog Timer to prevent hardware rebooting.
Martin
Martin
- achillis1
- Posts: 347
- Joined: Thu Oct 09, 2008 9:19 am
- Has thanked: 91 times
- Been thanked: 8 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Thanks Martin!!!
You have been very helpfull!
One last thing..
When I suppose to send "a NULL" to a device and more specific #define SPI_NULL (uint8_t) 0xF0
> What do they mean?
To just send via SPI macro a byte OR character with zero value?
I am suppose to that before I can read data from a specific device.
They gave me this guidelines
AND THIS LINK BUT I CANNOT MAKE ANY OUT OF IT, I DO NOT KNOW THE ARDUINO LANGUAGE
https://github.com/Wiznet/Arduino_WizFi250
Thank you,
Best Regards,
Andreas Achilleos
You have been very helpfull!
One last thing..
When I suppose to send "a NULL" to a device and more specific #define SPI_NULL (uint8_t) 0xF0
> What do they mean?
To just send via SPI macro a byte OR character with zero value?
I am suppose to that before I can read data from a specific device.
They gave me this guidelines
:#define SPI_NULL (uint8_t) 0xF0
#define SPI_ESC (uint8_t) 0xF1
#define SPI_F0 (uint8_t) 0x00
#define SPI_F1 (uint8_t) 0x01
#define SPI_SYNC (uint8_t) 0x02
#define SPI_XON (uint8_t) 0x03
#define SPI_XOFF (uint8_t) 0x04
#define SPI_ERR (uint8_t) 0x05
When you want to receive the data from WizFi250, You have to send SPI_NULL(0xF0) to WizFi250 using SPI interface like below.
>> CS to Low
>> Microseconds delay (10ms)
>> SPI Send NULL to WizFi250
>> Recive the data at the same clock that was sent SPI_NULL
>> Microseconds delay (10ms)
>> CS to High
AND THIS LINK BUT I CANNOT MAKE ANY OUT OF IT, I DO NOT KNOW THE ARDUINO LANGUAGE
https://github.com/Wiznet/Arduino_WizFi250
Thank you,
Best Regards,
Andreas Achilleos
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Hello Andreas,
For SPI you would typically only ever read or write however both are done simultaneously on every SPI transaction. I would guess that the SPI null value is arbitrary meaning it can literally be anything. So the code would look something like this.
>> CS to Low
>> Microseconds delay (10ms)
>> data = SPI Receive - Read byte from module
>> Microseconds delay (10ms)
>> CS to High
The value sent out for a receive is currently fixed to 0x55 using the SPI Master component. However if you instead use the CAL_SPI component then there is no macros for read or write, only a generic Master_Byte which allows you to read and write simultaneously.
10ms also seems like a big delay, should this be us or even ns? Edit aha I see now you have put Microseconds delay. DOH.
For SPI you would typically only ever read or write however both are done simultaneously on every SPI transaction. I would guess that the SPI null value is arbitrary meaning it can literally be anything. So the code would look something like this.
>> CS to Low
>> Microseconds delay (10ms)
>> data = SPI Receive - Read byte from module
>> Microseconds delay (10ms)
>> CS to High
The value sent out for a receive is currently fixed to 0x55 using the SPI Master component. However if you instead use the CAL_SPI component then there is no macros for read or write, only a generic Master_Byte which allows you to read and write simultaneously.
10ms also seems like a big delay, should this be us or even ns? Edit aha I see now you have put Microseconds delay. DOH.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- achillis1
- Posts: 347
- Joined: Thu Oct 09, 2008 9:19 am
- Has thanked: 91 times
- Been thanked: 8 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Hello Ben,
Thanks for the reply. Well it is confusing, they say microseconds and they have "ms" which stands for milliseconds yes? I will have to confirm that!
So I guess by saying that , in the SPI macro RECEIVE component there is embedded code that SENDS first 0x55 and then it RECEIVES?The value sent out for a receive is currently fixed to 0x55 using the SPI Master component. However if you instead use the CAL_SPI component then there is no macros for read or write, only a generic Master_Byte which allows you to read and write simultaneously.
If so, then based on the device instructions I should change that to 0xF0 ?
I have no idea what you mean here! Should I do that? (I use FlowcodeV4)However if you instead use the CAL_SPI component then there is no macros for read or write, only a generic Master_Byte which allows you to read and write simultaneously.
Thank you
Best Regards,
Andreas Achilleos
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Watchdoc timer connecting and setting prescaler
Hi Andreas,
Aha sorry I thought you were using v6, in v4 you probably need to use the component customisation to override the outgoing value for receives.
I have never encountered a device that required you to send and receive at the same time so I believe you won't need to customise anything and it should work as is with the new pseudo code breakdown I gave you.
Aha sorry I thought you were using v6, in v4 you probably need to use the component customisation to override the outgoing value for receives.
No the send and receive is simultaneous with SPI.in the SPI macro RECEIVE component there is embedded code that SENDS first 0x55 and then it RECEIVES?
I have never encountered a device that required you to send and receive at the same time so I believe you won't need to customise anything and it should work as is with the new pseudo code breakdown I gave you.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel