software: use DAC1 to generate square waves

main
EmaMaker 2021-05-16 14:56:21 +02:00
parent a569069575
commit aa02e2ba70
13 changed files with 15 additions and 4 deletions

0
Firmware/.gitignore vendored Normal file → Executable file
View File

0
Firmware/.vscode/extensions.json vendored Normal file → Executable file
View File

6
Firmware/.vscode/settings.json vendored Executable file
View File

@ -0,0 +1,6 @@
{
"files.associations": {
"type_traits": "cpp",
"utility": "cpp"
}
}

0
Firmware/include/sine.h Normal file → Executable file
View File

0
Firmware/include/square.h Normal file → Executable file
View File

0
Firmware/include/wave.h Normal file → Executable file
View File

0
Firmware/lib/README Normal file → Executable file
View File

0
Firmware/platformio.ini Normal file → Executable file
View File

2
Firmware/src/main.cpp Normal file → Executable file
View File

@ -14,5 +14,5 @@ void setup() {
}
FASTRUN void loop() {
generateSine(8150);
generateSquareDAC1(1000000, 50);
}

0
Firmware/src/sine.cpp Normal file → Executable file
View File

7
Firmware/src/square.cpp Normal file → Executable file
View File

@ -11,8 +11,8 @@ Lower frequency waves using nanoseconds is not needed and could actually causes
// Use FASTRUN to run code in RAM
FASTRUN void generateSquare(float frequency, int duty){
digitalWriteFast(DAC1_SEL, HIGH);
digitalWriteFast(DAC0_SEL, LOW);
digitalWriteFast(DAC0_SEL, LOW);
digitalWriteFast(DAC1_SEL, HIGH);
startGenerating();
if(frequency < 1000){
@ -48,6 +48,9 @@ FASTRUN void generateSquare(float frequency, int duty){
}
FASTRUN void generateSquareDAC1(float frequency, int duty){
digitalWriteFast(DAC0_SEL, LOW);
digitalWriteFast(DAC1_SEL, HIGH);
startGenerating();
if(frequency < 1000){

4
Firmware/src/wave.cpp Normal file → Executable file
View File

@ -14,10 +14,12 @@ void setupWaves(){
//Set DACs resolution to 12 bits
analogWriteResolution(12);
// Enable DAC0, from framework's analogWriteDAC0, place here from higher speeds
// Enable DAC0 and DAC1, from framework's analogWriteDAC0/DAC1, place here from higher speeds
// Reference voltage is 1.2V
SIM_SCGC2 |= SIM_SCGC2_DAC0;
DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS;
SIM_SCGC2 |= SIM_SCGC2_DAC1;
DAC1_C0 = DAC_C0_DACEN | DAC_C0_DACRFS;
}
// Wait time by counting clock cycles

0
Firmware/test/README Normal file → Executable file
View File