Hi all
id like to know if possible if i could alter the output of timer 2 within software, i have a port toggling at 40 hz but would like to alter this frequency to say 49 hz for the first 10 seconds of operation then revert back to 40 hz, at this point frequencys are examples i realise i need to adjust prescaler, postscaler and roll over but how if at all do i achive this ??? i did try using a c box with PR2 = 210-1 To change the rollover this gives a frequency of 49hz which is correct using a decision box if less than 10 seconds however it would not go back to 40hz after 10 seconds but the c code must be right as in hardware i got 49 hz I also changed timer tick to 99 as per rollover change
ive added a simple flow chart thanks in advance
bob
TIMER 2
Moderator: Benj
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: TIMER 2
Hi Bob.
The easiest way is by preloading the timer interrupt with a set value.
I have done that for a timer 0 example.
there is no reason why you can't do that for timer 2 as well.
The easiest way is by preloading the timer interrupt with a set value.
I have done that for a timer 0 example.
there is no reason why you can't do that for timer 2 as well.
Martin
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
Re: TIMER 2
hi martin
thanks for the reply my desired frequency is 40Hz therefore from your reply i did the following
using timer 2 i set
prescaler rate 1:16
postscaler 1:13
rollover 256
for nearest value to 40 is 37.560 Hz
then i did preload = 256 - (8000000/4x16x40) = 3125 therefore 256 - 3125 = -2869 ???
ive obviously gone wrong somewhere but following the calculation im unsure ??
bob
thanks for the reply my desired frequency is 40Hz therefore from your reply i did the following
using timer 2 i set
prescaler rate 1:16
postscaler 1:13
rollover 256
for nearest value to 40 is 37.560 Hz
then i did preload = 256 - (8000000/4x16x40) = 3125 therefore 256 - 3125 = -2869 ???
ive obviously gone wrong somewhere but following the calculation im unsure ??
bob
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
Re: TIMER 2
Hi martin
ive been playing around in software, using Timer 2 i cant seem to make the mentioned calcs work so i stuck with Timer 2 and made some changes with PR2 ive attached what i did and now for 20 seconds i get 51.90 Hz and the other 20 seconds i get 40 Hz then it repeats ive attached the flowchart and would value your advice
cheers bob
ive been playing around in software, using Timer 2 i cant seem to make the mentioned calcs work so i stuck with Timer 2 and made some changes with PR2 ive attached what i did and now for 20 seconds i get 51.90 Hz and the other 20 seconds i get 40 Hz then it repeats ive attached the flowchart and would value your advice
cheers bob
- Attachments
-
- TOGGLE PIN.fcfx
- (15.27 KiB) Downloaded 115 times
- Bachman
- Posts: 116
- Joined: Sun Sep 07, 2014 11:37 am
- Location: Hungary
- Has thanked: 9 times
- Been thanked: 53 times
- Contact:
Re: TIMER 2
Try to use these values (with 8 MHz clock):
Prescaler: 1:64
Postscaler: 1:13
PR2: 59 (40.064 Hz)
PR2: 48 (49.058 Hz)
Prescaler: 1:64
Postscaler: 1:13
PR2: 59 (40.064 Hz)
PR2: 48 (49.058 Hz)
- Attachments
-
- ScreenShot_153.png (190.73 KiB) Viewed 12090 times
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 24 times
- Contact:
- Bachman
- Posts: 116
- Joined: Sun Sep 07, 2014 11:37 am
- Location: Hungary
- Has thanked: 9 times
- Been thanked: 53 times
- Contact:
Re: TIMER 2
You can download the application from here (pCloud folder): https://u.pcloud.link/publink/show?code ... 0zDyoi9ySk
Please note: the application contain caclulations that are not available for every PIC microcontrollers. Check datasheet of the microcontroller. Eg.: you can use Timer 2 prescaler up to 128 but prescaler in PIC18F14K22, it can be only 1, 4 or 16.
Please note: the application contain caclulations that are not available for every PIC microcontrollers. Check datasheet of the microcontroller. Eg.: you can use Timer 2 prescaler up to 128 but prescaler in PIC18F14K22, it can be only 1, 4 or 16.