Society of Robots - Robot Forum

Software => Software => Topic started by: BuddingContraptionist on October 13, 2008, 04:53:57 PM

Title: atmega640 timing & embedded programming ?s
Post by: BuddingContraptionist on October 13, 2008, 04:53:57 PM
Hi again.  I want to use a timer interrupt to control the signal i send to my servo.  I'm new to this type of programming, but I've been reading the axon demo source code, the timerx8.h header in particular.

I thought that since the atmega640 runs at 16Mhz, and i was using an 8 bit timer (timer0) with a prescaler of 1024,
that I would have an interrupt rate of 256 / (16,000,000 / 1024) = 0.016384ms.

so I used the timerAttach function, and tried to use first a float, and then a double to count the iterations (ie, "msCount += 0.016384").  I thought at first that i could just do a "static float msCount=0.0", but it seemed like the thing wasn't powering up with that method... so i switch it to a global "volatile float msCount=0.0", and it runs.  But it fires at an entirely different (slower) rate than what I thought it would.  (it didn't count to 1000, or 1 second, in the 15 or so seconds that i watched it.)

Where did I do wrong?  And why can't i use a static variable in the interrupt function?
Title: Re: atmega640 timing & embedded programming ?s
Post by: Admin on October 14, 2008, 03:24:51 AM
The timerx8.h doesn't support the 640 very well. I have since created a timer640.h/.c in the newest beta version and hopefully caught most of the problems. Try it out and let me know if the problems still persist:
http://www.societyofrobots.com/axon/downloads/Axon_Source_beta.zip

The timerAttach function is part of the AVRlib library, so I don't quite yet understand it myself . . .