View previous topic :: View next topic |
Author |
Message |
mds
Joined: 06 Nov 2005 Posts: 29
|
12c509A timer0 power cycle problems |
Posted: Thu Dec 03, 2009 8:04 pm |
|
|
Hi all,
Such a simple task so I picked a simple pic out of my ancient pic bin:)
However I have run into a problem. The code will be the foundation of a simple timer. 30 and 60 seconds modes.
Its using the internal RC osc as I was not after super accuracy.
I wrote this simple code to test its timing. It should produce a pulse every 10ms. (using a timer0 compare routine)
I noticed on power cycling the device a number of times that the pulse width can vary. By almost 400us!
Just tested this with MCLR instead of power cycling. Same problem.
Once powered up and its "chosen" its freq its rock solid. A simple power cycle though and it can fire up with a different speed.
Tested using a JW device
Not sure what I'm missing.
Code: |
#include <12C509.h> //Change this line from 12c509 to 508 for 12c508 use
#use delay(clock=4000000)
#fuses INTRC,NOWDT,NOMCLR
#define o_tst PIN_B2 //test
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Simple timer
//
//Power up reads tiemr selector switch
//on start pb unit enters timer mode
//creates beep at end
#include <md_431.h>
#include <ver.c>
//Defines~~~~~~~
#define adjovf 50 //timer0 reload value (calibrated to make 10ms)
int1 tgletst;
//~~~~~~~~~~~~~~~~~~Toggle test pin~~~~~~~~~~~~~~~~~~~~~~~~~~
//Toggles testpin
void togl_tst()
{
tgletst=tgletst^1;
if(tgletst)
{
output_high(o_tst);
//tgletst=false;
} //end if tgle
else
{
output_low(o_tst);
//tgletst=true;
} //end if tgle
} //end toggle
//~~~~~~~~~~~~~~~~~~~counter 10ms~~~~~~~~~~~~~
//Updates various counters and timers.
void upd_timer()
{
int8 temp;
temp=get_timer0(); //get timer info
if(temp>=adjovf)
{
set_timer0(0); //reset counter
togl_tst();
}
} //end up_timer
//~~~~~~~~~~~~~~~~~~MAIN~~~~~~~~~~~~~~
void main()
{
output_high(o_bz); //buzzer off
set_tris_B(0xFF);
setup_counters(RTCC_INTERNAL,RTCC_DIV_256); //256us
set_timer0(0); //reset counter
//~~~~~~~~~~~~~~~'Main Loop'~~~~~~~~~~~~~
do
{
upd_timer();
}while(1); //end of main loop
} //end main
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 03, 2009 9:12 pm |
|
|
Put a crystal on it, or an oscillator. This will tell you whether it's the code
or the internal, real quick. |
|
|
mds
Joined: 06 Nov 2005 Posts: 29
|
|
Posted: Thu Dec 03, 2009 10:13 pm |
|
|
ok I think its to do with the osccal.
Because its an Eprom type(JW) I'm using for development its losing its calibration when I UV zap it.
Now to work out how to get a calibration number into the EPROM.?
I verified this by forcing 0x05h(OSCAL) to a known number on reset.
Every time now, same period:)
would never have noticed it when using OTPs cause the cal is not erased |
|
|
mds
Joined: 06 Nov 2005 Posts: 29
|
|
Posted: Thu Dec 03, 2009 10:23 pm |
|
|
a #ROM 0x3FF ={3200} seems to work.
Must make sure the programmer is set to program cal figures. (must remember to turn that off when it comes to writing the OTPs ;) |
|
|
|