Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Timer for PIC16F676 MCU

Status
Not open for further replies.

Manjuhb

Newbie level 6
Newbie level 6
Joined
Dec 2, 2015
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
149
Hi All,

I'm going to use pic16f676 in my new project. I want small conformation on timer. Is it possible to generate 20 minuts of dalay suing PIC16F676 IC. If yes plz provide me the sample code for this.



Thanks,
Manjunath
 

How accurate has to be this timming ? This is more a matter of proper selection of the crystal than actually setting Timer parameters, because choosing an oscillator with the value that is power of 2 of 1s (that is, dividing by the full prescaler range, gives an integer fraction of 1s), you get a tick proportional to 1s by counting, and an accuracy close to the crystal.
 

No, you cannot have 20 minutes delay. You have to use 4 MHz Crystal and get 500 ms timer interrupt. In Timer ISR use a counter to count required delay.

When the counter value is 2400 it will be 20 minutes.
 

Sorry, but I have to completely disagree with that.

Its true that with a 4MHz clock you can't directly produce a single timer cycle of 20 minutes but I see no mention of 4MHz in the original post. It can be used in RC mode or at a much lower clock frequency in which case it is perfectly feasible. In some designs I have worked on, admittedly using Hitachi MCUs rather than PIC, the crystal was 32.768KHz and such delays were easy to produce.

Even at higher clock frequencies there is no obligation to use 500mS, it can be any sensible combination of clock, prescaler and timer values to achieve the desired delay.

I've got a PIC here running at 48MHz clock that generates an accurate delay of four years. Anything is possible.

Brian.
 

Even at higher clock frequencies there is no obligation to use 500mS, it can be any sensible combination of clock, prescaler and timer values to achieve the desired delay

Indeed, it was not informed what should be the minimum resolution of this clock.
 

I use mikroE Timer Calculator Tool. It doesn't generate more than 500 ms delay if more than 4 MHz Clock is used. Also it generates max 500 ms delay for 4 MHz Clock.
 
I use mikroE Timer Calculator Tool. It doesn't generate more than 500 ms delay if more than 4 MHz Clock is used. Also it generates max 500 ms delay for 4 MHz Clock.
You are referring to the target value at the tool, not really the actual value coded. There is no way to directly divide the Oscillator frequency by a value of 2,000,000 ( =4000000Hz*0.5s ) even with the use of prescalers, meaning that it is expected a math approximation error.
 

You place blind faith in a calculator that only gives half the answer.

There is no mention of 4MHz in the original post but even if you assume that is what they want to use, according to my calculations the longest timer delay possible is 524.282mS. That's TMR1, prescaling by 8 and not giving it a starting value. The 16F676 can use any crystal or external clock frequency from (theoretical) zero to 20MHZ.

Brian.
 

If you use 8 MHz Clock or higher, Timer1, 500ms delay, PIC16 then it will not generate then Timer Calculator will not generate delay for that value.
 

If you use 8 MHz Clock or higher, Timer1, 500ms delay, PIC16 then it will not generate then Timer Calculator will not generate delay for that value.

Where do you see 500mS being mentioned, the original post asks for 20 minutes?

Options:
1. prescaling in software by counting faster interrupts
2. lower clock frequency
3. if high speed is still needed, use the TMR1 external LP oscillator
4. Use TMR0 to produce the clock input to TMR1 - it is posible, just needs some inventive thinking.

For example, connecting a 32.768KHz crystal across the LP oscillator pins, prescaling TMR1 by 8 and pre-loading it with 0x0FDC will produce interrupts once per minute (well - every 59.9996 seconds!) while letting the main processor run at up to 20MHz.

Brian.
 

I am just using a 500 ms delay as a base value with a counter to generate 20 minutes delay. it is only assumption and also because to generate 500 ms delay using Timer Calculator the Clock should be 4 MHz and so I assumed Clock as 4 MHz.

It is only my calculation.

If 1 MHz is enough for his project then Timer Calculator will generate 2 Second delay with 1 MHz Clock for PIC16F.
 

it is only assumption and also because to generate 500 ms delay using Timer Calculator the Clock should be 4 MHz and so I assumed Clock as 4 MHz.
...
It is only my calculation.

Unless you are able to provide a definite solution for the original question, all your assumptions are off-topic. Review post #7, and if you are not yet convinced, try using this tool, and will realize that there isn't any value that gives a similar accuracy of some RTC by using 4 or 8MHz crystal. Please, just add new remarks to this discussion, only if you can give a concrete answer for the OP.
 

I didn't understood what you said in post #7. I use Timer Calculator tool and it requires Crystal Frequency to be entered in MHz. I have to see if 32.768 KHz can be inputted to Timer Caluculator in Mhz format to get higher delay. I have not tried it yet.
 

ANY frequency within the limit of the PIC can be used, I just mentioned 32.768KHz as an example because it is easily available. If accuracy isn't important the internal RC oscillator can be used down to almost DC clock frequency.

Don't get hung up over the numbers produced by one calculator from one software company, the PIC is hardware and will work at any frequency lower than it's maximum rating and you can pre-load the timers to get almost any delay you want.

I don't use Mikro products but try entering 0.032768MHz to the calculator and see if it accepts it.

Brian.
 

As discussed in the thread bellow, there is a crystal in the range of MHz's, with which could obtain a tick of the clock divisible by an integer, so that by using a counter could achieve a precise value of 1s:

Considering that the Timer reload spends few core cycles, certainly would be necessary to make some fine tuning in reloaded values, but seems as a good start point.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top