WDT wake up from sleep

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Dave S
Posts: 39
Joined: Tue Jun 07, 2011 12:37 pm
Has thanked: 12 times
Been thanked: 5 times
Contact:

WDT wake up from sleep

Post by Dave S »

Hi all

I have written a very simple program for the PIC 12F629 using the internal RC oscillator. Basically I set the watchdog timer to 2.3 secs using prescaler 1:128, send a narrow pulse to an output and put the device into sleep.
The idea is to send the pulse once every 2.3 seconds by the WDT wakeup.
All works ok but every 4.6 seconds!

I tried the same program in MPLAB assembler and get 2.3 secs.

Any ideas please?

Code: Select all

#define MX_PIC

//Defines for microcontroller
#define P12F629
#define MX_EE
#define MX_EE_TYPE1
#define MX_EE_SIZE 128

//Functions
#define MX_CLK_SPEED 4000000
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif

//Configuration data
#ifdef _BOOSTC
#pragma DATA 0x2007, 0x3f8c
#endif
#ifdef HI_TECH_C
__CONFIG(0x3f8c);
#endif

//Internal functions
#include "C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h"

//Macro function declarations


//Variable declarations



//Macro implementations

void main()
{
	
	//Initialisation
	cmcon = 0x07;


	//Interrupt initialisation code
	option_reg = 0xC0;


	//WDT prescaler to 2.3S
	//C Code:
	option_reg = 0x1F; //WDT / 128





	//Data1
	//Output: 1 -> A4
	trisio = trisio & 0xef;
	if (1)
		gpio = (gpio & 0xef) | 0x10;
	else
		gpio = gpio & 0xef;


	//C Code
	//C Code:
	
	asm
	{
		nop
		nop
		nop
		nop
		nop
		nop

	}




	//Data0
	//Output: 0 -> A4
	trisio = trisio & 0xef;
	if (0)
		gpio = (gpio & 0xef) | 0x10;
	else
		gpio = gpio & 0xef;


	//C Code
	//C Code:
	sleep();
	asm
	{
		nop
	}




	mainendloop: goto mainendloop;
}

void MX_INTERRUPT_MACRO(void)
{
}




medelec35
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: WDT wake up from sleep

Post by medelec35 »

There is a know bug with V4 that when auto clear watchdog is enabled, all delay times are increased.
This has been fix with the latest free update due to be release very soon, so not long to wait.
There is a work around.
1) Disable auto clear watchdog.

2) For delays use this method:
E.g 4mins delay
4*60=240 = 240 seconds.
240/10*10E-3 = 24000 = number of 10ms has to elapse for 240 seconds
24000/240=100 If using a count of 240 on inner loop then outer loop must be 100.
delay.jpg
delay.jpg (43.92 KiB) Viewed 4992 times
Martin
Martin

Dave S
Posts: 39
Joined: Tue Jun 07, 2011 12:37 pm
Has thanked: 12 times
Been thanked: 5 times
Contact:

Re: WDT wake up from sleep

Post by Dave S »

Thanks for that Martin.

However, in this program auto clear watchdog is disabled and there are no loops or delays (except for a 6uS delay using asm nop commands.

Dave.

Rosenbaum
Flowcode V4 User
Posts: 25
Joined: Thu Feb 22, 2007 3:20 pm
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: WDT wake up from sleep

Post by Rosenbaum »

When I read youre posted c-code I read this:
main{
configuration,
watchdog reset,
puls,
sleep
Loop without watchdog reset (mainendloop: goto mainendloop;)
}
Your Program runs one time, the PIC begins to sleep, the watchdog let the PIC wakeup after ~2.3s but now there is now jump and the PIC runs ~2.3s in mainendloop. Than the watchdog reset the PIC again and it runs at adresse 0.

So, it is neccessery to put the pulse and the sleep in a own Loop.

medelec35
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: WDT wake up from sleep

Post by medelec35 »

Hi Dave.
Sorry, I did not read your post properly so got the wrong end of the stick.
I understand what your doing now.

Martin
Martin

Dave S
Posts: 39
Joined: Tue Jun 07, 2011 12:37 pm
Has thanked: 12 times
Been thanked: 5 times
Contact:

Re: WDT wake up from sleep

Post by Dave S »

Thanks Rosenbaum, that was the problem. All working fine now.

Dave S
Posts: 39
Joined: Tue Jun 07, 2011 12:37 pm
Has thanked: 12 times
Been thanked: 5 times
Contact:

Re: WDT wake up from sleep

Post by Dave S »

medelec35 wrote:Hi Dave.
Sorry, I did not read your post properly so got the wrong end of the stick.
I understand what your doing now.

Martin
Hi Martin, your answer is relevant to the next part of the code so thanks anyway.

Dave.

Post Reply