TIMER QUESTION

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
siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

TIMER QUESTION

Post by siliconchip »

hi all,
id like to ask a question regards timers is it possible to use timer 2 under 2 different macro names ie timer 2 and timer 2a and adding 2 interupts with said names so i can toggle the same output A0 but for a different amount of time ie timer2 for 20 seconds and timer2a for 60 seconds, i had a play but think i need 2 seperate timers with seperate outputs ie A0 and A1,thanks in advance

regards bob

medelec35
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 QUESTION

Post by medelec35 »

Hi Bob,
What I would do is use set a variable e.g called to set the SecondsDuration to the required seconds duration e.g 20.
So you could then use a decision branch within timer interrupt: if SecondsDuration = Seconds then seconds = 0; toggle pin.
The SecondsDuration could of course be any value.
Give that a try and if you get stuck, post a flowchart & I will help you further.
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: TIMER QUESTION

Post by Benj »

Hi Bob,

You cannot enable an interupt for a different macro. The way the underlying C code works only the first macro will ever be called.

You can however enable the interrupt several times for the same macro, you can also reference global variables in the timer interrupt macro and so you can do different rates and different things by making decisions on the variable.

Of course what Martin has said is also valid and you can keep the interrupt rate the same but have a software prescaler using a count variable and changing the count rollover using a global variable.

Hope this makes sense.

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: TIMER QUESTION

Post by siliconchip »

hi benj and martin

As always thanks for the replys im not too familiar with interupts are there any tutorials on them and how to use them a bit more in depth ?? Ive added my code and would appreciate it if you could give any pointers if ive over complicated it, its pretty much doing what i want now but i think ive duplicated to much code ?? Thanks in advance


Bob
Attachments
60Hzfreq v2.fcfx
(28.37 KiB) Downloaded 130 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: TIMER QUESTION

Post by Benj »

Hi Bob,

Looks ok to me. I've moved the duplicated code into a macro so you can just call the macro at various points.
60Hzfreq v2.fcfx
(23.11 KiB) Downloaded 147 times

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: TIMER QUESTION

Post by siliconchip »

Hi benj
Thats great many thanks

Bob

Post Reply