Go Down

Topic: Maximum pin toggle speed (Read 18 times) previous topic - next topic

westfw

Quote
Here is the sketch for a mega board or duamilove, don't know which you have but I have both which should generate 5.333MHz on Pin12

Ah.  The timer output to arduino pin mapping is different on Mega vs Diecimila; the signal shows up on pin 10 of the Diecimila.  Once I corrected for that I did indeed get 5.33MHz on pin 10.  Not a square wave, though; high for twice as long as it is low.

selfonlypath

#36
Oct 23, 2009, 05:08 am Last Edit: Oct 23, 2009, 05:09 am by selfonlypath Reason: 1
Quote
The timer output to arduino pin mapping is different on Mega vs Diecimila; the signal shows up on pin 10 of the Diecimila.  Once I corrected for that I did indeed get 5.33MHz on pin 10.

Glad it worked on your side.  ;)

Yes about pin, there are a bit different depending diecemila / duamilanove or mega eventhough the core sketch I gave you works on both.

I suggest you try my second sketch to find out ultimate case of 8 MHz on pin9 of diecemila instead of pin 11 of mega.

This is very useful doc from mem arduino member http://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0

Quote
Not a square wave, though; high for twice as long as it is low.

I'm sure you know this already but to not create confusion, the timers really work at correct frequencies but what happens is the arduino drivers and/or Atmega drivers are not enough fast to generate sharp PW waves. You might want to plug an external fast speed driver IC then you'll get nice waveform on your scope.



westfw

The first example really does generate a non-square wave.  It ought to be obvious: 5.33 = 16/3, so it's a 3-cycle waveform.  Lacking any sort of clock multiplier, that's going to be two cycles in one state and one in the other state...  (or, you're counting from 0 to 2 and flipping the bit at 1, so depending on which edges are involved, we have one state for 0,1 and the other for 2, or one state for 0, and the other for 1,2...)

The second example did generate a 8Mhz square wave (on  pin 10 of the diecimila, I think.  I didn't check both 9 and 10.)  Interpret the code as "count from 0 to 0 and toggle the output each time you finish (ie toggle every cycle, so output = clock/w))

The timer-generated output signals are quite a bit less interesting than the software-controlled ones, IMO.  Although people seem to have used such things to help drive LCD displays in a jitter-free fashion...  Hmm.

selfonlypath

About the first example, then you might want to try
- PWM, Phase & frequency correct
- PWM, Phase correct
because I gave you the code for fast PWM which goes higher freq but is less jitter stable.

For Fast PWM and OCR1A=3, timer1 frequency=16MHz/(1+TOP)=16MHz/3

For PWM phase and/or frequency correct, timer1 frequency is 16MHz/(2*TOP). Since your initial sofwtare controlled code was producing 2,667 MHz, you could choose OCR1A=TOP=2 in order to get 4MHz and setting OCR1B=1 to get 50% PWM. The phase and/or frequency correct does not provide maximum frequency but does provide very stable jitter due to its counting up-down timer construction.

Anyway, we're clearly pushing the limits of Atmega toggling outputs frequency  ;)

In any case, you need good external fast drivers otherwise signal distorsion will occur.


Circuitsville

Could you post the code?                Please?

The basic code I am using, from the Fade example, has a base frequency of about 500Hz.  To simplify and reduce the size of a lot of the inductors it would be nice to work at 50kHz.

bconley at circuitsvilleeng dot com

Go Up