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 support@ccsinfo.com

How to get a stable clock with 16f84?

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



Joined: 20 Nov 2006
Posts: 8

View user's profile Send private message

How to get a stable clock with 16f84?
PostPosted: Sat Jan 13, 2007 6:54 pm     Reply with quote

Hi, i'm just starting with microcontrollers and I think I have a problem.

Its a simple LED flasher, but... when i test the circuit, the delay between flashes are not equal, it doesn't stay 500ms 'ON' and then 500 ms 'OFF'.

can anyone tells me what am i doing wrong?

ps: im using a 10Mhz crystal and two 15pf capacitors for the oscilator.

thanks!
theteaman



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

PostPosted: Sat Jan 13, 2007 7:35 pm     Reply with quote

It's hard to say without looking at your code. Have you set the fuses appropriately?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 13, 2007 7:39 pm     Reply with quote

You need to post a short test program for a problem like this.
See my post in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=28377
It shows a test program to blink an LED. It's for a 16F84A, while
you're using a 16F84, but they're very similar chips.

Notice the code posted by "guest" a little further down in the thread.
He has left off one of the delay_ms() statements in his loop.
So his code never visibly blinks the LEDs, and one of them appears
to be on constantly. Then in his followup post, he attributes this to
moving his hand next the PIC.

Are you doing something like this ? (Leaving off the 2nd delay statement).
Schneider



Joined: 20 Nov 2006
Posts: 8

View user's profile Send private message

PostPosted: Sat Jan 13, 2007 9:43 pm     Reply with quote

The code I'm trying is this:


Code:

#include <16F84.h>
#fuses XT, NOWDT
#use delay(clock=10000000)

//=======================================
void main(void)
{

while(1)
  {
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }

}


... the problem is that the led blinks like this:

ON
500ms
OFF
200ms
ON
200ms
OFF
500ms
ON
100ms

looks like its not the same frequency each cycle... and the led blinks with difererent delay between the flashes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 13, 2007 11:22 pm     Reply with quote

For a 10 MHz crystal, you should use the HS (High Speed) oscillator mode.
If you use XT, it might not run, or it might run in a flaky manner.
Also, it wouldn't hurt to add the PUT fuse as well. Example:
Quote:

#include <16F84.h>
#fuses HS, NOWDT, PUT
#use delay(clock=10000000)
Schneider



Joined: 20 Nov 2006
Posts: 8

View user's profile Send private message

PostPosted: Sun Jan 14, 2007 1:59 pm     Reply with quote

thanks man, it worked.. :D
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