View previous topic :: View next topic |
Author |
Message |
Schneider
Joined: 20 Nov 2006 Posts: 8
|
How to get a stable clock with 16f84? |
Posted: Sat Jan 13, 2007 6:54 pm |
|
|
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
|
|
Posted: Sat Jan 13, 2007 7:35 pm |
|
|
It's hard to say without looking at your code. Have you set the fuses appropriately? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jan 13, 2007 7:39 pm |
|
|
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
|
|
Posted: Sat Jan 13, 2007 9:43 pm |
|
|
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
|
|
Posted: Sat Jan 13, 2007 11:22 pm |
|
|
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
|
|
Posted: Sun Jan 14, 2007 1:59 pm |
|
|
thanks man, it worked.. :D |
|
|
|