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.

Driving a servo motor- Timer0

Status
Not open for further replies.

Wingmax

New Member
This is continuous from "Driving a servo motor". This time we'll use Timer0 in P16f84A to generate the pulse width and the period of the pulse train.

The program sets up the Timer0 function, set the first value in the Timer0 register and wait for it to overflow. This value times the postscale is the pulse high duration. When Timer0 register overflows we set the pulse low and enter a second value (longer duration) and wait for another overflow. This value is to set the pulse period. When this overflow occurs, we set the
pulse high again and repeats the whole process.

The program doesn't use the interrupt routine.

View attachment servo motor_timer0_C.txt

Please refer codes in the main program to setup Timer0 function.
Because we set 16 mS as the pulse period, we have to use prescale of 1:64 so that Timer0 register will take more than 16mS before overflows.

This program will lead to the next program, which uses Timer0 and Timer1 and Timer1 interrupt routine........:)
 
Perhaps you should bear in mind this is the 21st century?, why are you posting about an antique from the last century?. Dump the long past it's sell by date F84, and use a modern device and a decent timer - TMR0 is the most useless of the PIC timers, and is only included for backwards compatibilty.
 
I like TMR0, it's limited but handy for a jiffy timer if you use the right crystal. I'm using it on one of my prototypes (the Ethernet one) for the RTC timebase.
9.8304MHz crystal on the 18F4620 is one of those 'magic' frequencies.
 
Me?

9.8304MHz
  • /65536 (TMR0) to create a very handy interrupt driven 150 Hz jiffy clock
  • it also multiplies by the 4 PLL in the 18F series for a 39.3MHz clock
  • works with any revision of the ENC28J60 (had an SPI speed bug)
  • perfect for a baud clock 0% error
 
blueroomelectronics said:
Me?

9.8304MHz
  • /65536 (TMR0) to create a very handy interrupt driven 150 Hz jiffy clock
  • it also multiplies by the 4 PLL in the 18F series for a 39.3MHz clock
  • works with any revision of the ENC28J60 (had an SPI speed bug)
  • perfect for a baud clock 0% error

But doesn't TMR0 need reseting in your program everytime it times out?, it's not self reseting like others? - this makes it require special consideration to maintain an accurate clock - check the real time clock application notes back from when TMR0 was all you got.
 
blueroomelectronics said:
Nope it's free running, and as accurate as the crystal. Just set the prescaler to 256:1 if you want a 150Hz interrupt. Easy
Opps: It's would need a 64:1 prescaler for 150Hz, or 128:1 for 75Hz.

Right, I see - you're selecting the crystal to compensate for the limitations of TMR0 - get your point now!.
 
The magic is it's also a perfect UART timebase, and a standandard crystal frequency.
Here they are... All common crystals
2.4576MHz
4.9152MHz
9.8304MHz
19.6608MHz

And it's spares the very useful TMR1 & TMR2
 
Nigel Goodwin said:
Perhaps you should bear in mind this is the 21st century?, why are you posting about an antique from the last century?. Dump the long past it's sell by date F84, and use a modern device and a decent timer - TMR0 is the most useless of the PIC timers, and is only included for backwards compatibilty.

Hi Nigel,

Perhaps you didn't read the end of the post. I will use different method in my next post, and I will use different PIC. This is just a begining of a discussion of using different method of producing pulses. I know the F84 is old and outdated, but do you know there are many people out there still using it. And for some beginners F84 is a good PIC to start. Don't forget, there are always someone new in this topic.

Also, as pointed out by Bill, TMR0 is not a bad feature. :D
 
Nigel Goodwin said:
But doesn't TMR0 need reseting in your program everytime it times out?, it's not self reseting like others? - this makes it require special consideration to maintain an accurate clock - check the real time clock application notes back from when TMR0 was all you got.


I don't think so. TMR0 will reset itself and increment from zero after it times out.
 
Wingmax said:
I know the F84 is old and outdated, but do you know there are many people out there still using it. And for some beginners F84 is a good PIC to start. Don't forget, there are always someone new in this topic.

No, it's not a good place to start! - it's a really bad place to start, why choose a long obselete, overly expensive device, with a low specification?.

By doing so you're just encouraging more people to use such outdated chips, I can see the point that there are ten year old tutorials out there on the net using it, but to write one in 2007 is just beyond belief!.

I would suggest you at least remove all references to the 84 and do the simple changes to use the 16F628 instead - the device that replaced the 84 last century.
 
Nigel Goodwin said:
No, it's not a good place to start! - it's a really bad place to start, why choose a long obselete, overly expensive device, with a low specification?.

By doing so you're just encouraging more people to use such outdated chips, I can see the point that there are ten year old tutorials out there on the net using it, but to write one in 2007 is just beyond belief!.

I would suggest you at least remove all references to the 84 and do the simple changes to use the 16F628 instead - the device that replaced the 84 last century.

I never thought using the F84 would cause so many hassels. It was not my intension to resurrect the F84. I was going to use the 628 next, and the 684 for ECCP function.
But my next one will be using Timer0 and Timer1( you might disagree again). So just thought may be started with Timer0 first. May be there are people out there wanted to know how to use Timer0. But anyway, using Timer0 is not my final goal, just an introduction.
 
Status
Not open for further replies.

Latest threads

Back
Top