Cours:PiPicoSDK : Différence entre versions
(→Configuration de la broche en mode PWM) |
|||
(Une révision intermédiaire par le même utilisateur non affichée) | |||
Ligne 2 : | Ligne 2 : | ||
https://www.raspberrypi.com/documentation/pico-sdk/ | https://www.raspberrypi.com/documentation/pico-sdk/ | ||
+ | cd pico-sdk | ||
+ | git submodule update --init | ||
+ | |||
Ligne 13 : | Ligne 16 : | ||
uint8_t pwmGpio = 0; | uint8_t pwmGpio = 0; | ||
− | |||
− | |||
− | |||
− | |||
int main() | int main() |
Version actuelle datée du 8 décembre 2024 à 22:18
https://www.raspberrypi.com/documentation/pico-sdk/ cd pico-sdk git submodule update --init
Pwm
Configuration de la broche en mode PWM
#include "pico/stdlib.h"
#include "/opt/pico-sdk/src/rp2_common/hardware_pwm/include/hardware/pwm.h"
uint8_t pwmGpio = 0;
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);
}
}