Hi there,
I am trying to use a single PWM pin on the RPi Pico to switch between two PWM frequencies: 1200Hz and 2200Hz. I would like to be able to switch between them at least at 1200 switches per second (re: Bell 202 modem + AFSK radio transmission). I am able to get the switching down to ~1ms between each pulse, which is not optimal. Is this the fastest I can switch PWM frequencies on the RPi Pico?
Here's an example of the function I'm using to implement the PWM at a given frequency (using https://github.com/khoih-prog/RP2040_PWM):
I am trying to use a single PWM pin on the RPi Pico to switch between two PWM frequencies: 1200Hz and 2200Hz. I would like to be able to switch between them at least at 1200 switches per second (re: Bell 202 modem + AFSK radio transmission). I am able to get the switching down to ~1ms between each pulse, which is not optimal. Is this the fastest I can switch PWM frequencies on the RPi Pico?
Here's an example of the function I'm using to implement the PWM at a given frequency (using https://github.com/khoih-prog/RP2040_PWM):
Code:
bool setPWM_manual(const uint8_t& pin, const uint32_t& top, const uint8_t& div, uint16_t& level, bool phaseCorrect = false) { _pin = pin; _phaseCorrect = phaseCorrect; _PWM_config.top = top; _PWM_config.div = div; // Limit level <= top if (level > top) level = top; _dutycycle = ( (uint32_t) level * 100000 / top); gpio_set_function(_pin, GPIO_FUNC_PWM); _slice_num = pwm_gpio_to_slice_num(_pin); pwm_config config = pwm_get_default_config(); // Set phaseCorrect pwm_set_phase_correct(_slice_num, phaseCorrect); pwm_config_set_clkdiv_int(&config, _PWM_config.div); pwm_config_set_wrap(&config, _PWM_config.top); // auto start running once configured pwm_init(_slice_num, &config, true); pwm_set_gpio_level(_pin, level); // Store and flag so that simpler setPWM_manual() can be called without top and div PWM_slice_manual_data[_slice_num].initialized = true; // From v1.1.0 //////////////////////////////// // Update PWM_slice_manual_data[] if ( (pwm_gpio_to_channel(_pin)) == PWM_CHAN_A) { PWM_slice_manual_data[_slice_num].channelA_div = level; PWM_slice_manual_data[_slice_num].channelA_Active = true; // If B is active, set the data now if (PWM_slice_manual_data[_slice_num].channelB_Active) { pwm_set_chan_level(_slice_num, PWM_CHAN_B, PWM_slice_manual_data[_slice_num].channelB_div); } } else if ( (pwm_gpio_to_channel(_pin)) == PWM_CHAN_B) { PWM_slice_manual_data[_slice_num].channelB_div = level; PWM_slice_manual_data[_slice_num].channelB_Active = true; // If A is active, set the data now if (PWM_slice_manual_data[_slice_num].channelA_Active) { pwm_set_chan_level(_slice_num, PWM_CHAN_A, PWM_slice_manual_data[_slice_num].channelA_div); } } else { return false; } pwm_set_enabled(_slice_num, true); //////////////////////////////// _enabled = true; return true; }
Statistics: Posted by bzzt_ — Wed Sep 25, 2024 10:10 pm