Answer the question
In order to leave comments, you need to log in
How to make a frequency generator on Arduino GPIO?
You need to get on the Arduino (Leonardo-compatible, ATmega32U4, 16MHz) on one of the GPIO pins a uniform signal with a frequency of 200 kHz. Ideally, a sine-shaped one, but a square one will do.
I see 2 approaches:
1) Somehow program the system timer so that it manages the GPIO itself (without processing the timer interrupt). I like this approach the most, but it is not clear whether it can be done this way.
2) Program the system timer, and hang on its interruption. In the interrupt, change the signal level on the GPIO.
Is the 1st approach possible?
If not, will the processor have enough speed to process everything in an interrupt (2nd approach)?
Answer the question
In order to leave comments, you need to log in
It is possible to use the timer/counter in CTC mode with the OCnA output toggle to match the OCRnA register. For the Arduino Leonardo Timer-Counter 1, this is the Digital 9 pin.
#include <ve_avr.h> // Используется библиотека VE_AVR
#define PIN_OC1A 9 // Пин Digital 9 - OC1A
void setup() {
DEV_TIMER1.setWaveGenMode(TimerW::CTC_OCRA);
DEV_TIMER1.setClockSelect(TimerW::Prescaler_1); // PR = 1
DEV_TIMER1.setOutputCompareA(39); // 16e6/(2*PR*(1+39)) = 200 kHz
DEV_TIMER1.setCompOutModeA(TimerW::Toggle);
pinMode(PIN_OC1A, OUTPUT);
}
void loop()
{
}
Because There is no DAC in this stone, then you can implement it on PWM with further smoothing.
PWM can work automatically after initialization, without the participation of the program. But in order to get a signal of a certain shape, it will have to periodically change values. Those. you will need a couple of timers, one for PWM, one for steps. Sine, and other non-linear things, can be done according to a pre-prepared table, bypassing it cyclically, saving computing resources.
In general, google function signal generator or waveform generator, there are many implementations, in particular on AVR.
PS If just a meander is suitable, then one timer in PWM mode is generally enough.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question