Timer and pwmout

hugoxp1

Member
Hi,

in manual 2, pg 141: "As each pwmout command resets the internal timer, the
pwmduty command is recommended on X1/X2 parts (after the initial pwmout)
to rapidly change the duty."


what i want to know is (using a 20X2): can I use a sub where i insert:

Code:
main:
    SetTimer 65411
    timer=0
    readadc10 C.1, w0 
    (...)
    w1=timer
and then use another sub to control a motor using pwmout?

Since they are in independent "subs" there will be a "problem"? How can this affect my timer variable in the main sub?

thanks
 

inglewoodpete

Senior Member
Each PICAXE has 1 set of variables which, in reality, are fixed registers (memory locations). So you have 1 set of variables for your whole programme. One set of timers etc etc.

Also, have a close look at Appendix 2 - Possible Conflicting Commands (Manual 2)
 
Last edited:

1dgjctgmln1

New Member
20x2 settimer help

I'm basically trying to reset a 20x2 every 3 seconds while it runs some other tasks in the foreground. Is settimer basically a timer that runs in the background? Can it be used to reset the chip every 3 seconds without interrupting other tasks and timers (pauses and such)?
 

inglewoodpete

Senior Member
Can it be used to reset the chip every 3 seconds without interrupting other tasks and timers (pauses and such)?
I think you're just using the wrong terms. I think what you're asking can be done.

Firstly, "Reset" is a term when used with microcontrollers, which means clear everything: all variables, timers, stacks, initialise I/O etc etc....and then recommence execution at the top of the code. I suspect that is not what you want, since you say "without interrupting other tasks and timers".

If I understand you correctly, every 3 seconds you want to interrupt anything else that may be happening, with the exception of a selected range of routines. If this is the case, you would have the Timer cause an interrupt which would set a variable (flag) and then return control to whatever foreground task that was interrupted. The foreground task would need to regularly check the status of this flag and then react according to what you want.

Am I on target or do you need to explain exactly what you want more clearly?
 

1dgjctgmln1

New Member
20x2 reset and settimer help

I want to reset all the values and timers and starts the program over from the beginning every 3 seconds regardless of whatever the program is doing at that moment. I hope I can do that with a timer that runs in the background. I'm going to have the rest of the program running in the foreground. The rest of the program is simple enough so I should be able to figure it out on my own. So settimer just runs in the background?
 

inglewoodpete

Senior Member
In that case, have a look at the Reset command. You'd need to put it in the interrupt routine, to be executed when the timer causes an interrupt.

I'm confused why you initially said "without interrupting other tasks and timers"
 

BeanieBots

Moderator
As each pwmout command resets the internal timer, the
pwmduty command is recommended on X1/X2 parts (after the initial pwmout)
to rapidly change the duty
It's the PWM timer that gets reset which causes a 'glitch' on the PWM pulse stream which is why pwmduty should be used.
 
Top