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)
{
}