Ed_B's blog


Submitted by Ed_B on Mon, 08/30/2010 - 16:09

click READ MORE to see the whole post

timerInterrupt_Match.pde  Copyright (c) 2010 Ed Bennett    Demo of setup for a compare-match timer2 interrupt for an Arduino AVR.  Timer2 counts up to a pre-defined value, then clears the counter and sets an interrupt which toggles an i/o pin.   The program generates a square wave with a period of about 30uS -- at the expense of the chip doing anything else. Slowing the interrupt rate will free up the processor, but the speed control values chosen for this example are to make the output go fast.

Happy Pins 7 -- video demo and Arduino code example

Submitted by Ed_B on Thu, 07/22/2010 - 23:10

I'm discovering that there was an unknown-unknown challenge in writing the timer-scheduler demo examples. It really shouldn't have been a surprise at all, but giving aesthetic structure to time with C code is an odd thing to do. It must be a little like composing music in code. That's something to ask around about. The previous posting had a demo video, but the code behind it was awful. I didn't understand what the mindset should be to use the timer-scheduler library. The right way to think about it in the context of rhythmic composition is pretty much limited to timer events controlling other timer events and generating outputs. Here's a video, and the Arduino sketch is below. Code is at http://code.google.com/p/timer-scheduler/


Flag Register

Submitted by Ed_B on Sun, 07/18/2010 - 22:34

In a previous post I described the use of flags in code and the cpu. Flags are data bits that are grouped into bytes called flag registers. The the flags can be True or False, also called Set and Clear. Flags can be read from or written to by the hardware in the cpu, and by the user's code. Some flags are only used internally by the cpu. An important use of flags in user code is in making and using timers. Here is a demo of using flags to control timing of some lamps, some rotary solenoids, and a very old dumb terminal. The Arduino controlls everything. The dumb terminal only prints messages from the Arduino.


Differences in Approach to Choosing a Timer Method

Submitted by Ed_B on Tue, 07/06/2010 - 23:04

 The timer-scheduler library gives three methods for using timer generated events in your code. 

  • Polling a flag attached to a timer.
  • Using callback functions that are activated by the timers.
  • Driving an i/o pin directly from the timer service (pin-direct method).
  Poll a Flag Callback Pin-direct
loop() will be interrupted during normal operation (this is usually ok)    X  
user code runs at every timer event (too much can choke the AVR)    X  
must attach a pin to a timer to see anything happen      X

can attach a pin to timer, but it's better to control the pin in the program

 X  X  
user code must be tight and fast (no delay(), minimal use of Serial.print(), etc.)    X  
should avoid using delay()  X won't
can have empty loop()    X  X
can use Timer.setHighTime() and Timer.setLowTime()  X  X  X
can use Timer.repeat()  X  X  


Timer-Scheduler Library Examples Using Three Different Methods

Submitted by Ed_B on Wed, 06/30/2010 - 12:47

I've been working on a  timer/scheduler library for fairly accurate, low speed timing of function calls on the Arduino. Using timers to schedule simple function calls, you can have multiple repeating events happening at the same time. As you know, this is very hard to do using delay().  The timer-scheduler library can give the appearance of multiple channels of independent activity. It looks kind of like multitasking. Maybe it is. Maybe it isn't. 

The timer-scheduler library provides eight (8) software timers. There are three methods for using a timer to make something happen. The first method is polling a flag. A flag is read from or written to by hardware and your code. A flag has two states: set (high) or clear (low). Flags tell you when something has changed in hardware. The second method uses callbacks. These are small functions you write. They fire off when a timer event happens.  The third method, pin-direct, attaches a software timer directly to a pin. The pin will go high and low based on the timer settings.  The videos are of the actual code samples running. The video for the flag-polling method and the callback methods is the same footage(!?) for both methods, because they look the same when they're running. The video for the pin-direct sketch has asymmetrical blink patterns because it was more fun to write it that way.

  READ MORE =====>

 Video for the flag-polling method and the callback method:

Using the Command Line to Interact with Google SVN During an Edit

Submitted by Ed_B on Mon, 06/14/2010 - 20:41

Now that the timer-scheduler code is safely stored in Google's SVN system, it's time to try a first edit. I'm using the Kate editor for my project. Kate is very minimal, but has most of the features I  want for simple projects like these. The Kate tools menu has a terminal window available. As you click around the files in your project, Kate will cd to the directory containing the file in the editor window. I'm issuing SVN commands from the terminal window. In the screenshots below, I'll check the project to see what's there, edit the TimerScheduler.cpp file by adding a "warning" to line 25 and save to my hard disk. Then run update in case I think I might need to merge my changes with someone elses (none required). Running status -v shows the modified file  flagged with "M". Then the change is committed to SVN. The project version increments to 3, even though only the TimerScheduler.cpp file was changed. The full version increment on each commit, no matter how small, is a feature of SVN. A checkout gives you get the "head" version that has all the most current files in it. I'll learn more about that soonly.

See what's there:
svn status -v

make changes, then save to hard  disk

READ MORE =====>

Setting Up a New SVN Project on Google Code

Submitted by Ed_B on Sat, 06/12/2010 - 20:14

I've been working on a  timer/scheduler library for fairly accurate, low speed timing of function calls on the Arduino. To share the code, I got the idea to set up a Google Code repository for the project http://code.google.com/p/timer-scheduler/ . This is new stuff for me, and was hard to figure out. I started with the unadorned project folder from my laptop. Google code projects can  use either the Mercurial or Subversion (SVN) version control systems. I chose SVN because I'd heard of it. I  did my setup from the command line in Ubuntu. Here's what I think finally worked.

Interrupt Driven Timer/Scheduler -- ISR mechanism

Submitted by Ed_B on Fri, 05/21/2010 - 16:56

The proposed timer/scheduler for fairly accurate, low speed timing of function calls is based on the Wire I2C library for the Arduino. I've borrowed the entire structure of the library, including naming conventions. The parallels between my proposal and the Wire library callback structure are pretty clear by comparing this diagram to the Wire diagram posted earlier.

( Read More =>)

A possibile scheme for an interrupt-driven software timer

Submitted by Ed_B on Sat, 05/15/2010 - 17:26

All the discussion about interrupts in the AVR and Arduino got me to thinking about how to set up a small handfull of software timers that could do fairly accurate, low-speed timing of function calls. As long as the function calls were brief, you should be able to schedule their activataion on a timed basis. Flowcharts to the rescue! Here's a plan for one channel of a multi-channel interrupt-driven timer I'd like to flesh out and try in an AVR. (read more)

Back from Outer Space

Submitted by Ed_B on Sat, 05/08/2010 - 21:19

Danny Bertner's robot-head work in progress sings along.


 The jaw is moved by a model servo. The control signal comes from a special track on the audio recording. It's karoke in reverse. To make the control track, we took the tracks on the original song and rearrnged them with Garage Band. The right channel contains the combined left and right channels of the original stereo recording. The left channel contains Danny singing an acapella accopaniment to the original song. The two tracks are locked together becase they're  part of the same MP3. This complexity was necessary because the instrumentals could not be sufficiently separated from the vocals to give a usable sound envelope for controlling the motor. In this method Danny is directly controlling the motion of the robot mouth with the strength of his own voice. An envelope follower circuit tracks the loudness of Danny's voice and produces a control voltage fed into an Arduino. The Arduino uses the control voltage to move the servo which moves the robot's jaw mechanism. (more details => )

Syndicate content