parent
b859235dfa
commit
eb2184603e
|
@ -10,5 +10,4 @@
|
|||
#define MAX_ACHIEVABLE_FREQ 1000000
|
||||
|
||||
void generateSine(float);
|
||||
void generateSines(float, float);
|
||||
void setupSine();
|
|
@ -10,5 +10,5 @@ void setup() {
|
|||
}
|
||||
|
||||
FASTRUN void loop() {
|
||||
generateSines(10000, 10000);
|
||||
generateSine(1000000);
|
||||
}
|
|
@ -50,37 +50,4 @@ FASTRUN void generateSine(float frequency){
|
|||
//Write the voltage on the DAC
|
||||
*(volatile aliased_int16_t *)&(DAC0_DAT0L) = LUT[(int)phase];
|
||||
}
|
||||
}
|
||||
//Write the DAC with using some parts of framework's Arduino.h, for higher speeds
|
||||
// Use FASTRUN to run code in RAM
|
||||
typedef int16_t __attribute__((__may_alias__)) aliased_int16_t;
|
||||
|
||||
FASTRUN void generateSines(float frequency1, float frequency2){
|
||||
startGenerating();
|
||||
|
||||
// Phase accumulator
|
||||
float phase1 = 0;
|
||||
float phase2 = 0;
|
||||
|
||||
//Constrain frequency
|
||||
frequency1 = constrain(frequency1, 0, MAX_ACHIEVABLE_FREQ);
|
||||
frequency2 = constrain(frequency2, 0, MAX_ACHIEVABLE_FREQ);
|
||||
|
||||
// Phase increment at each step
|
||||
float delta_phi1 = frequency1 / SAMPLE_FREQ * LUT_SIZE;
|
||||
float delta_phi2 = frequency2 / SAMPLE_FREQ * LUT_SIZE;
|
||||
|
||||
while(generateWave){
|
||||
// increment phase
|
||||
phase1 += delta_phi1;
|
||||
phase2 += delta_phi2;
|
||||
|
||||
// handle wraparound
|
||||
if (phase1 >= LUT_SIZE) phase1 -= LUT_SIZE;
|
||||
if (phase2 >= LUT_SIZE) phase2 -= LUT_SIZE;
|
||||
|
||||
//Write the voltage on the DAC
|
||||
*(volatile aliased_int16_t *)&(DAC0_DAT0L) = LUT[(int)phase1];
|
||||
*(volatile aliased_int16_t *)&(DAC1_DAT0L) = LUT[(int)phase2];
|
||||
}
|
||||
}
|
|
@ -42,4 +42,5 @@ FASTRUN void generateSquare(float frequency, int duty){
|
|||
delayCycles(dutyLowCycles);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -12,11 +12,9 @@ void setupWaves(){
|
|||
analogWriteResolution(12);
|
||||
|
||||
// Enable DAC0, from framework's analogWriteDAC0, place here from higher speeds
|
||||
// Reference voltage is 1.2V
|
||||
SIM_SCGC2 |= SIM_SCGC2_DAC0;
|
||||
DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS;
|
||||
// Enable DAC0, from framework's analogWriteDAC0, place here from higher speeds
|
||||
SIM_SCGC2 |= SIM_SCGC2_DAC1;
|
||||
DAC1_C0 = DAC_C0_DACEN | DAC_C0_DACRFS; // 3.3V VDDA is DACREF_2
|
||||
}
|
||||
|
||||
// Wait time by counting clock cycles
|
||||
|
|
Loading…
Reference in New Issue