• 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.

Calculating and setting PIC TMR LOOP

Status
Not open for further replies.

camerart

Active Member
Hi,
I have a PIC program using TMR0 and need to calculate and set the TIMER LOOP to be 20MS.
The clock speed is 4MHz.
Can anyone help me set it please?
Thanks,
Camerart.
 
Last edited:

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Yup!!! Is this for "Ye Olde pic18f4431" per chance??

The 4mHz will give 1uS clocks... You need to count to 20,000.. presetting TMR0L and TMR0H with 0xB1DF and set T0CON with 0x88.. ( timer on.. 16 bit.. prescaler off.. ) you need to preset each interrupt..
If you only have the 8 bit timer, then you'll need the prescaler.. A prescaler of 128 and a preset of 99 will do the job..
T0CON = 0x86.. TMRO = 0x63..
 

camerart

Active Member
Yup!!! Is this for "Ye Olde pic18f4431" per chance??

The 4mHz will give 1uS clocks... You need to count to 20,000.. presetting TMR0L and TMR0H with 0xB1DF and set T0CON with 0x88.. ( timer on.. 16 bit.. prescaler off.. ) you need to preset each interrupt..
If you only have the 8 bit timer, then you'll need the prescaler.. A prescaler of 128 and a preset of 99 will do the job..
T0CON = 0x86.. TMRO = 0x63..
Forsooth 'tis an 18LF2520. (I've got one on a test PCB, before moving to an 19LF4431)

Here's the program, with only the above T0CON and TMR0 settings, before trying your program from the other thread. (NOTE: bit 6 is '1'?? for 8BIT)

It takes a while to see both LOOPs. Cut and paste from LINE 152, into H-UART for test in Oshonsoft SIM.

Thanks, C.
 

Attachments

Last edited:

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member

camerart

Active Member
Hi I,
I've just realised that the program needs a radio module HC-12. to test it. I'll do that next.
I've connected 1x SERVO as a test.
C.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top