Author Topic: atmega640 timing & embedded programming ?s  (Read 3127 times)

0 Members and 1 Guest are viewing this topic.

Offline BuddingContraptionistTopic starter

  • Jr. Member
  • **
  • Posts: 44
  • Helpful? 0
atmega640 timing & embedded programming ?s
« 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?
« Last Edit: October 13, 2008, 05:02:12 PM by BuddingContraptionist »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,696
  • Helpful? 173
    • Society of Robots
Re: atmega640 timing & embedded programming ?s
« Reply #1 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:

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


Get Your Ad Here