Hi. I am feeding the input frequency to pin 15 from a high-precision DDS oscillator.
Dividing this frequency by 2, I feed the resulting frequency to the output pin 14.
If the output frequency is less than 100 Hertz, then the division is exactly 2 times.
If I increase the output frequency, (for example, input frequency = 10000 Hertz, output frequency 5000 Hertz). But this is no longer being done. For example, the output frequency can be 5000.000 Hertz or 5000.500 Hertz or 5001.000 Hertz.
The frequency sometimes increases by exactly 0.500 or 1,000 Hertz.
How can I fix this error?
Dividing this frequency by 2, I feed the resulting frequency to the output pin 14.
If the output frequency is less than 100 Hertz, then the division is exactly 2 times.
If I increase the output frequency, (for example, input frequency = 10000 Hertz, output frequency 5000 Hertz). But this is no longer being done. For example, the output frequency can be 5000.000 Hertz or 5000.500 Hertz or 5001.000 Hertz.
The frequency sometimes increases by exactly 0.500 or 1,000 Hertz.
How can I fix this error?
Code:
//---2025.01.21-----------------------------------------------------------------//#include "hardware/gpio.h" //#include "hardware/pwm.h" ////------------------------------------------------------------------------------//#define SIGNAL_PIN 15 //Input pin //uint Output_pin=14; //Output pin //uint k_del=1; //Koeff. =2 ////------------------------------------------------------------------------------//bool signal_out; //uint signalSlice,slice_num; ////------------------------------------------------------------------------------//void setup() //{ // //---Настраиваем на выход-----------------------------------------------------// pinMode(Output_pin, OUTPUT); // //---setup signal counter-----------------------------------------------------// signalSlice = setup_pwm_counter(SIGNAL_PIN); // //----------------------------------------------------------------------------//} ////------------------------------------------------------------------------------//void loop() //{ //} ////------------------------------------------------------------------------------//uint setup_pwm_counter(uint gpio) //{ // //---can only use input on channel B------------------------------------------// assert(pwm_gpio_to_channel(gpio) == PWM_CHAN_B); // slice_num = pwm_gpio_to_slice_num(gpio); // pwm_config cfg = pwm_get_default_config(); // pwm_config_set_clkdiv_mode(&cfg, PWM_DIV_B_RISING); // pwm_config_set_clkdiv(&cfg, 1.f); // pwm_config_set_wrap(&cfg, k_del-1); // pwm_init(slice_num, &cfg, false); // gpio_set_function(gpio, GPIO_FUNC_PWM); // //---register interrupt handler-----------------------------------------------// pwm_clear_irq(slice_num); // pwm_set_irq_enabled(slice_num, true); // irq_set_exclusive_handler(PWM_IRQ_WRAP, on_pwm_wrap); // irq_set_enabled(PWM_IRQ_WRAP, true); // //----------------------------------------------------------------------------// pwm_set_enabled(slice_num, true); // return slice_num; //} ////------------------------------------------------------------------------------//void on_pwm_wrap() //{ // pwm_clear_irq(signalSlice); // gpio_put(Output_pin, signal_out); // signal_out =! signal_out; //} ////------------------------------------------------------------------------------//Statistics: Posted by Aleks_2024 — Tue Jan 21, 2025 7:23 pm — Replies 0 — Views 49