Timer 2 Tutorial

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1181
Joined: Wed Dec 31, 2008 3:37 pm
Contact:

Timer 2 Tutorial

Post by Steve001 »

Morning All

Is there a tutorial for setting and using timer 2 ?

have found a few posts on here and excel sheet etc but these not making sense

wanting to set on Eico modules

Steve
Success always occurs in private and failure in full view.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9180
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Timer 2 Tutorial

Post by medelec35 »

Hi Steve,
Lest assume your are after a 1000Hz interrupt frequency.
1) Run flowchart and add the timer interrupt, select timer 2, then select properties.
2) Download the great timer app from here.
3) After extracting and running app Select More check box, just in case the exact frequency is not possible.
4) Enter the Oscillator speed, in the case 48000000
5) On flowchart interrupt properties select the Prescaler rate drop-down and see if maximum is 1:16 or 1:64 then select the maximum correct prescaler on the timer app.
In the case of ECIO 1:16.
6) Enter the target frequency of 1000 on the time app then select Do it!

7)The settings you should set timer 2 (I have highlighted) to are then displayed in the app Results window:
Timer2 tutoral..png
(74.4 KiB) Downloaded 7275 times
Enter then within flowchart timer 2 properties:
Timer2 Int settings.png
(48.91 KiB) Downloaded 7275 times
Hope this helps.

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1181
Joined: Wed Dec 31, 2008 3:37 pm
Contact:

Re: Timer 2 Tutorial

Post by Steve001 »

cheers martin will have a go and see how i get on

Steve
Success always occurs in private and failure in full view.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9180
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Timer 2 Tutorial

Post by medelec35 »

Your welcome Steve.
Out of curiosity, do you have an interrupt frequency in mind?
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1181
Joined: Wed Dec 31, 2008 3:37 pm
Contact:

Re: Timer 2 Tutorial

Post by Steve001 »

not got a clue to be honest was going to try 1000Hz like you said and see if it works correctly - maybe not the correct way to go
wanting to generate an internal event at 20msec's

Steve
Success always occurs in private and failure in full view.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9180
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Timer 2 Tutorial

Post by medelec35 »

Steve001 wrote:wanting to generate an internal event at 20msec's
That would be one way to go.
All you do is place count variable that increments by one within the interrupt macro.
E.e

Code: Select all

Count = Count +1
then have a decision branch

Code: Select all

If Count  = 20 then count = 0 : Do whatever as another 20ms has elapsed since last here e.g. toggle an output.
How I derived 20 was 1000/50 = 20

The 1000 = interrupt frequency.
50 = 1/required time period = 1/20E-3

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1181
Joined: Wed Dec 31, 2008 3:37 pm
Contact:

Re: Timer 2 Tutorial

Post by Steve001 »

Thanks martin

bit more clear now thank you for explaining

trying to finish some ongoing projects after erm cough months :oops:

Steve
Success always occurs in private and failure in full view.

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1181
Joined: Wed Dec 31, 2008 3:37 pm
Contact:

Re: Timer 2 Tutorial

Post by Steve001 »

attached test file not behaving as expected runs at warp factor 10

not sure what is wrong was hoping A0 to be 50Hz and A5 to be 1Hz, have 506 and 102 admittedly not checked on a scope found my lead to be iffy :x
used Hz on my fluke

Steve
Attachments
timer 2.fcfx
(14.21 KiB) Downloaded 185 times
Success always occurs in private and failure in full view.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9180
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Timer 2 Tutorial

Post by medelec35 »

One way is attached.
Hopefully only thrusters are engaged this time. :lol:

Martin
Attachments
timer 2 V2.fcfx
(15.44 KiB) Downloaded 211 times
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1181
Joined: Wed Dec 31, 2008 3:37 pm
Contact:

Re: Timer 2 Tutorial

Post by Steve001 »

cheers martin

simulation looking better will try on hardware tomorrow :mrgreen:

what does this do ?

Code: Select all

(int_count1Hz = 0) || (int_count1Hz = 100)
Steve
Success always occurs in private and failure in full view.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9180
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Timer 2 Tutorial

Post by medelec35 »

Hi Steve,
Mentioned

Code: Select all

||
in this post

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1181
Joined: Wed Dec 31, 2008 3:37 pm
Contact:

Re: Timer 2 Tutorial

Post by Steve001 »

working thank you martin

Steve
Success always occurs in private and failure in full view.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 9180
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Contact:

Re: Timer 2 Tutorial

Post by medelec35 »

Hi Steve,
Glad its working for you.
Thanks for the update

Martin
Martin

Post Reply