Cours:PiPicoSDK

De troyesGEII
Aller à : navigation, rechercher
Pico-pinout.png

https://www.raspberrypi.com/documentation/pico-sdk/


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);
    }
}