avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Problem with interrupt on a MEGA8535


From: Philipp Burch
Subject: Re: [avr-gcc-list] Problem with interrupt on a MEGA8535
Date: Tue, 19 Feb 2008 19:27:34 +0100
User-agent: Thunderbird 2.0.0.9 (Windows/20071031)

Hi
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
}

Now for the weird part. This all above seems to work fine unless I update "servo" too often. As seen below:

// More code goes by...

            servo = 100;
            for (i=100;i<215;i+=2)
            {
                servo = i;
Well, what does "too often" mean? Match runs through its full range (0 - 1999) every 20ms (right?), so if you adjust "servo" several times, the comparison "match == servo" will never be true. What you might need could be some double-buffering, just as it is implemented in hardware for the output-compare-unit of Timer1. You have your global "servo" variable just like now, but you test "match" against a copy of "servo" which you update whenever "match" gets set to zero. And you should note, that "match == servo" will never be true if "servo" is set to zero, because match can't be 0 at this position (except it overflows for any reason...).

Philipp




reply via email to

[Prev in Thread] Current Thread [Next in Thread]