PDA

View Full Version : TMR0 interrupt. Counter pauses?



Kaya Onur
- 3rd March 2011, 12:44
Hi everybody,
I want to obtain servo control pulses. 50Hz (1520us center puls) using a 16F88 TMR0 interrupt. Running 8MHz (therefore 2MHz from FOSC/4) with 1/256 prescaler.

In the interrupt handler right after entry, I preload the TMR0 counter then PULSOUT. It is a very basic code.

It seems that the counter pauses during the PULSOUT because the outcoming signal's period is lengthened by the puls duration.

I tried different TMR0 values. Some does work fine some doesn't. By working fine I mean that the outcoming signal's period (therefore frequency) doesn't change with regard to puls duration.

Any idea?

Code for the interrupt handler:

DISABLE
INTERRUPT_HANDLER:
TMR0=160 'Tried different values here. Some work fine some doesn't.

PULSOUT SERVO, Duration 'SERVO is a SYMBOL for PORTA.2
LOW SERVO 'Just a precaution...

INTCON.2=0 'Interrupt flag cleared.
RESUME
ENABLE

cncmachineguy
- 3rd March 2011, 12:58
Hi everybody,
I want to obtain servo control pulses. 50Hz (1520us center puls) using a 16F88 TMR0 interrupt. Running 8MHz (therefore 2MHz from FOSC/4) with 1/256 prescaler.

In the interrupt handler right after entry, I preload the TMR0 counter then PULSOUT. It is a very basic code.

It seems that the counter pauses during the PULSOUT because the outcoming signal's period is lengthened by the puls duration.

I tried different TMR0 values. Some does work fine some doesn't. By working fine I mean that the outcoming signal's period (therefore frequency) doesn't change with regard to puls duration.

Any idea?

Code for the interrupt handler:

DISABLE
INTERRUPT_HANDLER:
TMR0=160 'Tried different values here. Some work fine some doesn't.

PULSOUT SERVO, Duration 'SERVO is a SYMBOL for PORTA.2
LOW SERVO 'Just a precaution...

INTCON.2=0 'Interrupt flag cleared.
RESUME
ENABLE

If the TMR is disabled when entering the INT, then it is not counting. Therefore thr duration of PULSOUT will change the timing.

Move PULSOUT to your main loop. Set a flag in your INT. Then in your main loop, if the flag is set, execute PULSOUT and clear the flag.

Kaya Onur
- 3rd March 2011, 13:24
If the TMR is disabled when entering the INT, then it is not counting. Therefore thr duration of PULSOUT will change the timing.

Move PULSOUT to your main loop. Set a flag in your INT. Then in your main loop, if the flag is set, execute PULSOUT and clear the flag.

Thank you Bert.

I didn't know that DISABLE had this effect. I will try this ASAP.

In the PBP help documentation, they say that DISABLE doesn't actually generate code. So I am a bit confused how it stops the counter without generating any code.

Thank you very much.

cncmachineguy
- 3rd March 2011, 14:16
I am not certain it is, I ment to say "If it is disabled". But in any event you should move the PULSOUT

Bruce
- 3rd March 2011, 14:55
DISABLE doesn't generate code, but it does keep PBP from placing interrupt checking code in your interrupt handler. It doesn't stop any timers.

Kaya Onur
- 3rd March 2011, 15:23
DISABLE doesn't generate code, but it does keep PBP from placing interrupt checking code in your interrupt handler. It doesn't stop any timers.

My pleasure... :)

So how would you think on the lengthened period issue ?

I removed the PULSOUT into the main loop as Bert said. It looks OK now.