# PIC frequency

Discussion in 'General Electronics Chat' started by RG23, Jan 4, 2011.

1. ### RG23 Thread Starter Active Member

Dec 6, 2010
301
2
How to obtain 1 hz signal from 1Mhz internal clock oscillator in PIC 16f887 without using timer?

if anyone has an idea please let me know

Thank you ​

Jan 18, 2008
5,699
909
3. ### RG23 Thread Starter Active Member

Dec 6, 2010
301
2
I just want to use the internal 1Mhz clock

no timers or time delays

4. ### ke5nnt Active Member

Mar 1, 2009
384
15
A 1Hz signal from the internal osc? Hmmm... might not be possible. You can usually only get the internal oscillator down to 32KHz, but that's still about 31,999Hz too fast for you. Some MCUs let you use a single resistor on the OSC1 pin to create a variable oscillator frequency (variable by the fact that you can change it by changing the value of the resistor) in ER mode. Even still, a MCU with a 4MHz internal clock with a 1MΩ resistor on OSC1, the clock only goes down to 200KHz.

I'm not an expert believe me, I suppose there may be some combination of bit changes and prescaler maybe that could get you close? Or the right combination of resistor and capacitor for an external R/C oscillator, but I would be surprised if you were able to achieve a 1 Hertz clock from the internal OSC.

5. ### RG23 Thread Starter Active Member

Dec 6, 2010
301
2
ke5nnt
Senior Member

But I think there must be some way out to achieve any frequency from the clock frequency.

6. ### thatoneguy AAC Fanatic!

Feb 19, 2009
6,357
718
Toggle a pin with each loop through a program. Every instruction takes 4 instructions per second, so your output should be around 100kHz. Use a divide by 100k circuit for a 1Hz output.

Internal clock will not be as accurate as a crystal, especially if using the 1Hz for a timebase.

I'd suggest a 32.768kHz crystal and a divide by 32,768 circuit (15 bit counter overflow at 1Hz).

This is the only way to do it without using delays, timers, or interrupts in the code. Those are integral parts of the controller to allow you to get various frequencies on outputs.

7. ### jpanhalt AAC Fanatic!

Jan 18, 2008
5,699
909
It's impossible to do what the OP wants. You use a timer, or you use a time-delay loop. You can port the internal osc. to the outside and deal with it there, but the OP apparently doesn't want that either.

When someone wants to do something that is impossible, my first question is why? Usually they are daydreaming or simply don't understand what they want to do.

John

8. ### RG23 Thread Starter Active Member

Dec 6, 2010
301
2
Is it possible to implement a real time clock and then use the 1 second interval from that clock to get the 1Hz signal?

9. ### RG23 Thread Starter Active Member

Dec 6, 2010
301
2
I have a code in which all three timers of PIC 16F887 are being used for some or the other functions.

My objective is to clear the counter on LCD display after every 1 second. When I try to clear one of the timers and use them for 1 second, I am not getting the desired result.
It is actually interfering the whole operation. The three timers in that code are used in the Interrupt Service routine of the program.

Hence I want to know if there is any way I can keep resetting the counter after every one second.

Also when I tried using the delay loop of 1 second it did not work.

Basically I want something similar to timer that will keep running for one second in the background and help me reset the counter after every one second.

I hope I made it clear.

Thank you

10. ### thatoneguy AAC Fanatic!

Feb 19, 2009
6,357
718
Is there a reason the LCD must be updated every second, exactly?

uCs usually run at speeds where the LCD can be updated several times per second while doing many other operations in between.

Is there a larger overall loop that will update the LCD many times a second, thus when the variable that changes each second will also change on the LCD at the next update.

Using a realtime clock will also work, but would require additional circuitry to extract the seconds.

11. ### Markd77 Senior Member

Sep 7, 2009
2,803
594
If any of your current timer interrupts are regular then they could be used.
eg. if one of them interrupts 200 times a second, you could just put a counter in there that excecutes your LCD update every 200 times.

12. ### RG23 Thread Starter Active Member

Dec 6, 2010
301
2
yes the LCD must be updated every second.

Actually I just want something similar to a 1 second timer that runs in the background continuously

But I am unable to modify any of the timers nor does it work with any delay loop

13. ### t06afre AAC Fanatic!

May 11, 2009
5,939
1,222
The human eye will not notice if the display is updated with some jitter. In fact updating every second will make the display kind of fuzzy. If you use a timer to trigger an interrupt service routine(ISR). I would have used a counter variable in the ISR. And then set a flag then it was time to update the display

14. ### jpanhalt AAC Fanatic!

Jan 18, 2008
5,699
909
I can understand not wanting a 1 sec delay loop somewhere in the program. If you are using Assembly, you can easily add up or measure the execution time of the whole program and branches. Thus, the whole program can be inserted into and becomes part of the delay loop. Of course, depending on what else is going on, the refresh won't always be exactly 1 sec, unless you make all possible branches the same time-length. I use NOP's. Obviously, that can get complicated quickly.

If that doesn't cut it, then your idea of getting a 1 sec time signal from somewhere else -- another smaller PIC -- makes sense.

John

15. ### spinnaker AAC Fanatic!

Oct 29, 2009
5,114
1,195
There is no need to modify the timer itself. Just the interrupt routine.

As Markd77 said you just need to figure out how often one of those timers is running it's interrupt handler. Put in a counter, when the counter reaches X, update the display and reset the counter.