Skip to content

Add set frequency #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions examples/Beginner/Waveform_Generator/Waveform_Generator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ void generate_waveform(int cmd)
} else {
break;
}

dac1.stop();
delay(500);
if (!dac1.begin(AN_RESOLUTION_8, dac_frequency * N_SAMPLES, N_SAMPLES, 32)) {
Serial.println("Failed to start DAC1 !");
}
delay(500);

// Change frequency.
dac1.frequency(dac_frequency * N_SAMPLES);
break;

default:
Expand Down
9 changes: 9 additions & 0 deletions src/AdvancedDAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ int AdvancedDAC::stop()
return 1;
}

int AdvancedDAC::frequency(uint32_t const frequency)
{
if (descr && descr->pool) {
// Reconfigure the trigger timer.
dac_descr_deinit(descr, false);
hal_tim_config(&descr->tim, frequency);
}
}

AdvancedDAC::~AdvancedDAC()
{
dac_descr_deinit(descr, true);
Expand Down
1 change: 1 addition & 0 deletions src/AdvancedDAC.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AdvancedDAC {
void write(SampleBuffer dmabuf);
int begin(uint32_t resolution, uint32_t frequency, size_t n_samples=0, size_t n_buffers=0);
int stop();
int frequency(uint32_t const frequency);
};

#endif /* ARDUINO_ADVANCED_DAC_H_ */