Cours:PiPicoSDK : Différence entre versions
Ligne 2 : | Ligne 2 : | ||
https://www.raspberrypi.com/documentation/pico-sdk/ | https://www.raspberrypi.com/documentation/pico-sdk/ | ||
+ | |||
+ | |||
+ | =Pwm= | ||
+ | |||
+ | ==Configuration de la broche en mode PWM== | ||
+ | |||
+ | <source lang=cpp> | ||
+ | #include "/opt/pico-sdk/src/rp2_common/hardware_pwm/include/hardware/pwm.h" | ||
+ | |||
+ | uint8_t pwmGpio = 0; | ||
+ | |||
+ | void on_pwm_wrap() { | ||
+ | pwm_clear_irq(pwm_gpio_to_slice_num(pwmGpio)); | ||
+ | } | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | // Tell the pwmGpio pin that the PWM is in charge of its value. | ||
+ | gpio_set_function(pwmGpio, GPIO_FUNC_PWM); | ||
+ | // Figure out which slice we just connected to the pwmGpio pin | ||
+ | uint slice_num = pwm_gpio_to_slice_num(pwmGpio); | ||
+ | // Get some sensible defaults for the slice configuration. By default, the | ||
+ | // counter is allowed to wrap over its maximum range (0 to 2**16-1) | ||
+ | pwm_config config = pwm_get_default_config(); | ||
+ | // Set divider, reduces counter clock to sysclock/this value | ||
+ | // Fmli = 125MHz / (clkdivValue * wrapValue) | ||
+ | pwm_config_set_clkdiv(&config, 16.f); | ||
+ | pwm_config_set_wrap(&config,(uint16_t)1024); | ||
+ | // Load the configuration into our PWM slice, and set it running. | ||
+ | pwm_init(slice_num, &config, true); | ||
+ | |||
+ | while (1) | ||
+ | { | ||
+ | pwm_set_gpio_level(pwmGpio, fade); | ||
+ | } | ||
+ | } | ||
+ | </source> |
Version du 23 mars 2023 à 12:17
https://www.raspberrypi.com/documentation/pico-sdk/
Pwm
Configuration de la broche en mode PWM
#include "/opt/pico-sdk/src/rp2_common/hardware_pwm/include/hardware/pwm.h"
uint8_t pwmGpio = 0;
void on_pwm_wrap() {
pwm_clear_irq(pwm_gpio_to_slice_num(pwmGpio));
}
int main()
{
// Tell the pwmGpio pin that the PWM is in charge of its value.
gpio_set_function(pwmGpio, GPIO_FUNC_PWM);
// Figure out which slice we just connected to the pwmGpio pin
uint slice_num = pwm_gpio_to_slice_num(pwmGpio);
// Get some sensible defaults for the slice configuration. By default, the
// counter is allowed to wrap over its maximum range (0 to 2**16-1)
pwm_config config = pwm_get_default_config();
// Set divider, reduces counter clock to sysclock/this value
// Fmli = 125MHz / (clkdivValue * wrapValue)
pwm_config_set_clkdiv(&config, 16.f);
pwm_config_set_wrap(&config,(uint16_t)1024);
// Load the configuration into our PWM slice, and set it running.
pwm_init(slice_num, &config, true);
while (1)
{
pwm_set_gpio_level(pwmGpio, fade);
}
}