View previous topic :: View next topic |
Author |
Message |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
External Clock PIC16F688 |
Posted: Wed Mar 21, 2012 8:00 am |
|
|
Hey guys, I got very surprised the other day when I removed the crystal from my board and the PIC kept working. Surprisingly, I couldn't use the sleep routine. So, my doubt is... What fuse do I need to activate in order to my PIC works with an external clock???
I found this fuse: #fuse EC_IO. But I couldn't get my PIC working with an external clock. I put 4MHz crystal with two capacitors in the respective pins, but even with this, my PIC didn't start.
Thanks beforehand guys. _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Mar 21, 2012 8:19 am |
|
|
post your code and compiler versioin |
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Wed Mar 21, 2012 8:32 am |
|
|
I'm using Version 4.038. And the part of the code is this one.
Code: |
#fuses XT, NOWDT, NOBROWNOUT, NOPUT, NOMCLR, EC_IO
#use delay(clock=4000000)
|
And I think the fuses is the problem about this, because I don't have any more things in my code. If I remove the EC_IO the PIC will start working with or without an external clock. So, how can I tell to my compiler to use an external clock???. _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Mar 21, 2012 9:43 am |
|
|
HAVE YOU TRIED HS instead of XT ??
#fuse PUT,HS ...... ??
YOU NEED TO allow PUT to operate with an ext crystal
you can see if you are getting oscillation on the osc OUT pin
of the pic on an oscilloscope too
you might s have a problem with the size ( or connection) of your crystal phasing capacitors too |
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Wed Mar 21, 2012 9:58 am |
|
|
But if I'm using a 4MHz Crystal... Can I use the HS fuse??? _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Wed Mar 21, 2012 10:34 am |
|
|
Whoa.
You can only have _one_ oscillator fuse. If you are using an external oscillator module, EC_IO, and _get rid of HS, or XT_.
If you are using an external crystal (not a complete oscillator), then get rid of EC_IO, and just have HS or XT.
Having both gives an invalid oscillator configuration for either setup.....
The oscillator settings are mutually exclusive.
At 4Mhz, XT should work. HS 'may work' if the crystal gain is low, but can cause problems on some chips, with the input being overdriven.
However if you have a particularly low gain crystal, then HS may be needed.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Wed Mar 21, 2012 10:50 am |
|
|
Which value's capacitor you suggest??? I have 10pF. _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Mar 21, 2012 11:04 am |
|
|
depedns on XTAL SPEC
for 4 mhz AT cut i'd try 22pf or 33pf with XT fuse |
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Wed Mar 21, 2012 12:14 pm |
|
|
OK guys... I'm trying to do this... because I think that my biggest problem is that I'm using the sleep routine, but, doesn't work, that's anybody has an example that works??? _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Wed Mar 21, 2012 12:37 pm |
|
|
Walk first.
Prove your chip is working, and at the right frequency.
Just do a 'toggle pin' routine, with a specified delay, and time that the delay is right.
Only move on to trying to sleep, once you are sure this is all working.
On sleep, depends what you want to wake it up?. Remember you can only wake using things that keep running, when the chip is asleep, The data sheet tells you what can do this. So, hardware interrupt - yes. Serial receive - no. Watchdog - yes, but relatively innacurate. Also remember it takes a long time to wake up the crystal.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Wed Mar 21, 2012 12:57 pm |
|
|
Guys, even I can't turn on a LED with this... what is the problem??? I can't find it... can someone point it out??? Please???
Code: | #include <16F688.H>
#fuses NOWDT, NOBROWNOUT, PUT, NOMCLR, EC_IO
#use delay(clock=4000000)
short flag_timer=0;
#int_TIMER1
void TIMER1_isr(void)
{
set_timer1(0);
flag_timer=1;
}
void main()
{
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_8);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(true){
sleep();
if(flag_timer)
{
flag_timer=0;
output_high(pin_c5);
delay_ms(100);
output_low(pin_c5);
}
}
} | [/code] _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Wed Mar 21, 2012 1:08 pm |
|
|
Change T1_EXTERNAL to T1_INTERNAL
Are you using an external oscillator or a xtal with capacitors? Your FUSE is set up for an external oscillator. For a xtal, use either XT or HS. _________________ David |
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Wed Mar 21, 2012 1:13 pm |
|
|
I tried all of them. If I remove the sleep routine, it will work, so I'm confuse... I need and external crystal to make the interruption, right??? that's anybody has a clue about what is going on here with this code??? _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Mar 21, 2012 2:35 pm |
|
|
Code: |
#include <16F688.H>
#Fuses XT,NOWDT,PUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,
#fuses NOIESO,NOFCMEN,
#use delay(clock=4000000)
void main() {
while(true){
output_toggle(pin_c5);
delay_ms(100);
}
}
|
does this work for you or not ??? |
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Wed Mar 21, 2012 2:42 pm |
|
|
Well... I'm trying to save energy, I have to save it... that's why I need to work with the sleep mode, So I'm trying to use the external clock to generate an interruption with the external clock, but, it doesn't work. _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
|