|
From: | Paulo Marques |
Subject: | Re: [avr-gcc-list] Problem with interrupt on a MEGA8535 |
Date: | Tue, 19 Feb 2008 18:48:11 +0000 |
User-agent: | Thunderbird 1.5.0.14 (X11/20071210) |
dlc wrote:
I have an odd problem and I'm hoping that by trying to explain it I can solve it...What I have is an timer overflow ISR that tics off every 10us. I've coded it thusly:// variables at the top (global) //ISR variables, volatile by nature volatile uint16_t t_10us=0; volatile uint32_t t_1ms=0; volatile uint16_t repeat=0; volatile uint16_t match=0; // The single servo used uint8_t servo = 150; // past initializations and such ... SIGNAL(SIG_OUTPUT_COMPARE0) /* * 10 microsecond ISR */ { t_10us++; if (t_10us > 100) { t_1ms++; //1ms background clock t_10us = 0; repeat++; if (repeat == 19) { repeat = 0; SPIN = 1; //raise servo pin high match = 0; //start servo timer } } match++; //increment every 1 if (match == servo) SPIN=0; //drop servo bit }
You really should just use the output compares to do timed pulses, instead of wasting all your cpu power just doing this.
Anyway, you problem is that you're updating servo in the main loop while updating match in the interrupt, so chances are they are running paste each other...
The proper way to write that code (apart from using output compares) would be something like:
volatile uint16_t next_pulse; SIGNAL(SIG_OUTPUT_COMPARE0) { match++; // increment every 1 if (match > next_pulse) SPIN = 0; // drop servo bit else SPIN = 1; // raise servo pin high if (match >= 20000) { next_pulse = servo; match = 0; //start servo timer } } I hope this helps, -- Paulo Marques Software Development Department - Grupo PIE, S.A. Phone: +351 252 290600, Fax: +351 252 290601 Web: www.grupopie.com "Prediction is hard. Especially of the future." Niels Bohr
[Prev in Thread] | Current Thread | [Next in Thread] |