Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

external crystal vs. internal timer/wdt

Status
Not open for further replies.

Steve P

New Member
Hey guys...me again. :lol:

As posted in a previous topic, https://www.electro-tech-online.com/threads/good-computer-programming-book.17679/ I decided to use a 16F877A for the project I'm starting and ordered it from Microchip on Saturday night/Sunday morning.

I'm on the Sparkfun website (**broken link removed**) and I see my pic, but the description reads that the pic can operate at 20mhz with an external crystal. I know that the crystal is the "heartbeat" of the pic and I understand the crystal to create the timing cycles needed to operate the program. Am I correct in my assumption?

Also, how does an external crystal differ from the INTERNAL timers in a pic? I think I understand what the watch dog timer is but can someone, if you have the time, explain the differences and why each is significant?

I know I ask a lot of questions, but you guys are experts! I've been getting a lot of FREE engineering consulting...lol. 8)
 
Steve P said:
I know that the crystal is the "heartbeat" of the pic and I understand the crystal to create the timing cycles needed to operate the program. Am I correct in my assumption?
Yes. The geek word for heartbeat is clock. Also please note that one PIC instruction is carried out every 4 heartbeats because the PIC has a lot of housekeeping to do.

So a PIC using 20MHz can at maximum toggle a port pin 5,000,000 times per second, giving 2.5MHz output.

Steve P said:
Also, how does an external crystal differ from the INTERNAL timers in a pic?

External crystal or internal oscillator is responsible for the "heartbeat" of the PIC. These are not timers.

Surprise!!! a PIC also does not have timers in the sense that there are only series of binary counters. If one feeds the counters with either a fixed frequency pulses or external pulses, the counter counts up or overflow in a certain period of time. A certain event will be triggered when it overflowed. By reading the value of the counters in realtime or checking/allowing/expecting these events to happen, one can use/view the counters as "Timers".

Steve P said:
I think I understand what the watch dog timer is but can someone, if you have the time, explain the differences and why each is significant?

Do you want to know why there are three timers and what are the main difference between them and when to use which timer? I want to know too. Here is just a tiny bit of the answer:
choosing which timer to use on the 16F877

Steve P said:
I know I ask a lot of questions, but you guys are experts! I've been getting a lot of FREE engineering consulting...lol.
I'm no better. Started learning PIC just a month ago.
 
Steve P said:
I know that the crystal is the "heartbeat" of the pic and I understand the crystal to create the timing cycles needed to operate the program. Am I correct in my assumption?

Yes. Just like the quartz in your watch, it is used along with an oscillator circuitry to generate a constant heartbeat.

Steve P said:
Also, how does an external crystal differ from the INTERNAL timers in a pic? I think I understand what the watch dog timer is but can someone, if you have the time, explain the differences and why each is significant?

You are talking of three different things here :

- The "heartbeat" is generated by the PIC's oscillator and your external quartz. You could also use a simple resistor/capacitor combo instead of the quartz (check your datasheet). There are even PICs with internal clocks that do not need any external heartbeat. But the point is, the PIC needs a heartbeat as much as you need one. Without one, it won't run.

- An internal timer in the PIC will help you keep track of time in your applications.

- The watchdog timer is a simple mechanism that can be used to avoid software lockups )think of an infinite loop). The term "watchdog" is common in the software world. When a process stops responding for some amount of time, an external mechanism, the watchdog, will reset the locked up process. This is exactly what happens in the PIC. When you decide to use the watchdog timer, you have to tell it several times a second that "hey, I'm ok". If the watchdog doesn't hear from you for too long a period of time, it's gonna assume you're lost in a loop and just reset the PIC.
 
The watchdog timer is a simple mechanism that can be used to avoid software lockups )think of an infinite loop). The term "watchdog" is common in the software world. When a process stops responding for some amount of time, an external mechanism, the watchdog, will reset the locked up process. This is exactly what happens in the PIC. When you decide to use the watchdog timer, you have to tell it several times a second that "hey, I'm ok". If the watchdog doesn't hear from you for too long a period of time, it's gonna assume you're lost in a loop and just reset the PIC.

The watchdog timer is also useful for setting up software delays. For eg: when a watchdog timer counts down from a value (say FFH), when it reaches zero, it will generate an interrupt so this can be used to trigger events.
 
Electrix said:
The watchdog timer is also useful for setting up software delays. For eg: when a watchdog timer counts down from a value (say FFH), when it reaches zero, it will generate an interrupt so this can be used to trigger events.

Yep, but that's not its normal usage, and the other timers can do that too.

One difference the WDT has to other timers is that it has its own "heartbeat". If for some reason you lose the main oscillator signal on CLKIN, the WDT still runs fine. But if you loose your main clock, you're already in deep caca so I'm not sure how this can be very useful...

[edit]

Just remembered that some timers can have external clocks, and don't necessarily clock themselves to the PIC's clock...
 
Thanks for your responses guys. So let me get this straight...I still need a crystal in order to make the PIC work? Thats cool. I think I'm just going to lock myself in the bathroom when I get home and try to make sense of the datasheet.

Maybe I can get a crystal from radioshack...they seem like they'd be pretty standard.

Wish me luck... :?
 
Steve,

You can still experiment with your 16F876 without a crystal. Use the RC type oscillator. It's basically a capacitor/resistor combo which oscillates (I have no idea why/how this actually works, but it works) connected to CLKIN. Check out the datasheet, section 14.2.3 RC Oscillator.
 
cool.

Thanks Joel.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top