IW2FVO,
To read the timer:
variable var word
variable = tmr1
To write the timer:
tmr1 = variable
Its just that simple....
IW2FVO,
To read the timer:
variable var word
variable = tmr1
To write the timer:
tmr1 = variable
Its just that simple....
Dave Purola,
N8NTA
EN82fn
thanks,
if I write tmr1= 64 then the compiler gives me :
>> error 113..... pbpp18.lib580 : symbol not previously defined (tmr1 ) and then the same message but lib588, lib927, lib 933.
So the point is still : how to read / write TMR1 ?
Any help is appreciated.
Thanks
Ambrogio
Hi,
It's easy but I'm afraid it's not THAT easy - there is no TMR1 register (hence the error). Instead TMR1 consists of TWO 8bit regsiters, TMR1L and TMR1H.
The straight forward way to write it is to doAnd the straight forward way to read it isCode:TMR1L = 0 TMR1H = 0When reading TMR1 this way there's a slight posibillity that TMR1L overflows right in between reading TMR1H and TMR1L giving you a wrong result. To prevent that the easiest way is to simply STOP the timer before reading it. If that's not possible there are other ways to cater for that - and there are tricks that allows you to read it in one go if needed but lets keep it as simple as possible for now.Code:myVar VAR WORD myVAR.HighByte = TMR1H myVAR.LowByte = TMR1L
/Henrik.
If you are using the Timer Template, then there's no reason to read or write to the Timer directly. It is handled for you by the template.
If you are not using the template, you should at least use the Timer Reload routine from the template.
To maintain a constant frequency that also accounts for interrupt latency, the reload value must be ADDED to the current value in the Timer.
Just reloading a value into the Timer will give a frequency output, but accuracy and consistency will suffer.
There are other ways to ADD the reload value to the Timer, but you must know exactly how many instructions it takes to do the addition.
The routine in the template is already known to take 8 instruction cycles.
The template automatically adjusts for that amount of time.
With the template, if you tell it you want 100hz ... you get 100.0 Hz.
With all of that said ... you still haven't revealed whether you want a Fixed frequency or Variable frequencies?
It makes a huge difference.
DT
Thanks to everybody for the assistance.
yes, I need a fixed frequency so I can use the timer tamplate. >> Is this table applicable to pic18f4523 ?
Additional question:
>> what is the purpose of bit_7 ( rd16 ) in the t1con register? How to use it ?
>> what is the purpose odf the RESETFLAG? yes/no in the DT _int ?
Regards,
Ambrogio
The table is applicable to all PIC's, but it doesn't include the higher OSC frequencies of the 18F's.
If your interrupt frequency is greater than 160 Hz (80 Hz Full Cycle), you don't need to worry about the table.
Just set Prescaler to 1 and Freq to your frequency.
The RD16 bit buffers the highbyte of the Timer so that both bytes can be read or written without stopping the Timer.
The Timer Template will not work with RD16 set.
With interrupts that require you to manually clear the interrupt flag, setting RESETFLAG to YES will allow DT_INTS to clear it for you.
DT
Thanks again Darrel for the great assistance.
regards,
Ambrogio
IW2FVO
North Italy
Bookmarks