Hi all,
Here the benchmark with my Teensy 3.1. The goal was to known the max output frequency on DAC (A14 output). The conditions of tests are:
. Teensy must generate an sine wave and square wave in "good form" with minor distortion or best, no distorsion.
. Teensy program don't do nothing else.
. These tests has been processed 3 times to be more precise.
Sorry in advance because I have only one digital oscilloscope and I can not put photo of wave sine output.
The dynamic sine calculous has been tested but the output frequency is low. The benchmark results are not in the sheet.
View attachment 2790
sine program here:
/*
Sine generator.
It works with A14/DAC on Teensy 3.1
Autor: Bruno Poultier.
Goal: Testing the max frequency available on A14/DAC with sine wave
Tests conditions:
. The same source has been compiled whith various CPU clocks: 96Mhz, 72Mhz, 48Mhz and 24Mhz
. 12 bits resolution (max)
. the output is free of charge (no capacitor, resistor, etc)
. the output signal must be clean (beautiful sine)
This example code is based on PJRC project.
*/
float _2pi = 3.14159265 * 2;
// 2 * pi() ~ 6.28 / 0.01 => 628 dots
const int DOT = 628;
float amplitude[DOT];
/**
Fill array with all values.
arg: none
return: none
**/
void fillAmplitude(){
for ( int x = 0 ; x < DOT ; x++){
amplitude[x] = (sin( x * 0.01 ) * 2000.0 ) + 2050.0F;
} // eo for
}
/**
Create the sine wave with the precalculated values
arg: none
retur: none
**/
void preCalculatedAmplitude(){
// sine wave
while(1){
for ( int i = 0 ; i < DOT ; i++){
analogWrite(A14, amplitude
);
}//eo for
}//oe while 1
}
/**
create sine wave dynamically and send value to the A14.
arg: none
return: none
**/
void computeSine(){
float phase = 0.0F;
while(1){
float amp = sin(phase) * 2000.0 + 2050.0;
analogWrite(A14, (int) amp);
phase = phase + 0.01;
if (phase >= _2pi) phase -= _2pi;
}//eo while 1
}
/**
initialize all mandatory elements
arg: none
return: none
**/
void setup() {
analogWriteResolution(12); // DAC setup.
fillAmplitude();
}
void loop() {
preCalculatedAmplitude();
// computeSine();
}
Square program here:
/*
Square generator.
It works with A14/DAC on Teensy 3.1 only.
Autor: Bruno Poultier.
Goal: Testing the max frequency available on A14/DAC with square output wave
Tests conditions:
. The same source has been compiled whith various CPU clocks: 96Mhz, 72Mhz, 48Mhz and 24Mhz
. 12 bits resolution (max)
. the output is free of charge (no capacitor, resistor, etc)
. the output signal must be clean (beautiful sine)
This example code is pjrc project samples.
*/
elapsedMicros usec = 0;
/**
initialize all mandatory elements
arg: none
return: none
**/
void setup() {
analogWriteResolution(12); // DAC setup.
}
void sleep(unsigned int t){
while ( usec < t )
usec = usec - t;
}
void loop() {
int _Zero = 1000; // 0 could be bad without delay.
int _One = 4000; // middle of max output capability
// Results from oscilloscope HITACHI V-212
// time slope to pass from 0 to 1.
// 1 | 0.7us
// 2 | 0.65us
// 3 | 0.65us
// 4 | 0,65us
// 5 | 0.7us
// 6 | 0,7us
// 7 | 0.64us
// 8 | 0.66us
// 9 | 0.64us
//10 | 0.66us
//15 | 0.68us
//20 | 0.6us
//50 | 0.65us
//100 | 0.62us
int t = 1 ; // tempo. We need to add a delay to have a nice square signal. No delay gives one "triangular" wave generated when CPU clock < 72Mhz. After, it's sine.
while(1){
analogWrite(A14, _Zero);
//delayMicroseconds(t);
analogWrite(A14, _One);
//delayMicroseconds(t);
}
}
Sorry for my poor english :-(
Bruno.