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

12c509A timer0 power cycle problems

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



Joined: 06 Nov 2005
Posts: 29

View user's profile Send private message

12c509A timer0 power cycle problems
PostPosted: Thu Dec 03, 2009 8:04 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 03, 2009 9:12 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 03, 2009 10:13 pm     Reply with quote

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 Smile
mds



Joined: 06 Nov 2005
Posts: 29

View user's profile Send private message

PostPosted: Thu Dec 03, 2009 10:23 pm     Reply with quote

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 ;)
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