Skip to content

ArtScienceLab/ARDUINO_ClockDivider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Clock Divider

This is a patch for an Arduino UNO to divide an input audio rate (48kHz) clock to a movement rate (120Hz) clock. It is a relative straightforward patch that uses interrupts.

It does, however, not use the relatively slow digitalWrite() but direct register manipulation as documented here. This also means that it is not usable on different Arduino’s.

Teensy

Since the incoming audio clock rate is 48kHz each period is 20.8333 microseconds. We expect that each interrupt is correctly handled registered. The margin of error is a bit less then half this period so about 8 microseconds. However when measuring the Arduino (using the internal pullup resistors) we see the following:

10:30:52.763 -> min 8168µ, max 8340µ, diff 172µ, current 8312µ
10:30:53.777 -> min 8168µ, max 8340µ, diff 172µ, current 8312µ
10:30:54.757 -> min 8168µ, max 8336µ, diff 168µ, current 8332µ
10:30:55.752 -> min 8124µ, max 8340µ, diff 216µ, current 8272µ
10:30:56.734 -> min 8124µ, max 8340µ, diff 216µ, current 8332µ
10:30:57.736 -> min 8168µ, max 8336µ, diff 168µ, current 8248µ
10:30:58.716 -> min 8168µ, max 8340µ, diff 172µ, current 8312µ

Measurement is done for the last 240 measurements and the minimum and maximum period for 400 periods is reported every second. The difference between minimum and maximum should be zero the period should be 20.83333 * 400 = 8333.3333 microseconds. The difference should be less than 20 microseconds otherwise audio samples have been skipped (as is the case here).

Using an other microcontroller running very similar code (a Teensy) the measurement starts to look better:

13:49:05.503 -> min 8331µ, max 8336µ, diff 5µ, current 8334µ
13:49:05.503 -> min 8331µ, max 8336µ, diff 5µ, current 8334µ
13:49:05.503 -> min 8331µ, max 8336µ, diff 5µ, current 8332µ
13:49:05.503 -> min 8330µ, max 8337µ, diff 7µ, current 8332µ
13:49:05.503 -> min 8330µ, max 8337µ, diff 7µ, current 8334µ
13:49:05.503 -> min 8331µ, max 8335µ, diff 4µ, current 8333µ
13:49:05.961 -> min 8331µ, max 8336µ, diff 5µ, current 8333µ
13:49:06.946 -> min 8331µ, max 8336µ, diff 5µ, current 8333µ
13:49:07.945 -> min 8331µ, max 8336µ, diff 5µ, current 8334µ
13:49:08.954 -> min 8331µ, max 8336µ, diff 5µ, current 8334µ

Credits

Developed by Joren Six at IPEM, University Ghent for the ASIL lab of de Krook.

About

Audio rate to movement rate Arduino patch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages