Initial Release
This commit is contained in:
12
pwm/hello_pwm/CMakeLists.txt
Normal file
12
pwm/hello_pwm/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
add_executable(hello_pwm
|
||||
hello_pwm.c
|
||||
)
|
||||
|
||||
# Pull in our pico_stdlib which pulls in commonly used features
|
||||
target_link_libraries(hello_pwm pico_stdlib hardware_pwm)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(hello_pwm)
|
||||
|
||||
# add url via pico_set_program_url
|
||||
example_auto_set_url(hello_pwm)
|
||||
34
pwm/hello_pwm/hello_pwm.c
Normal file
34
pwm/hello_pwm/hello_pwm.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
// Output PWM signals on pins 0 and 1
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/pwm.h"
|
||||
|
||||
int main() {
|
||||
///tag::setup_pwm[]
|
||||
|
||||
// Tell GPIO 0 and 1 they are allocated to the PWM
|
||||
gpio_set_function(0, GPIO_FUNC_PWM);
|
||||
gpio_set_function(1, GPIO_FUNC_PWM);
|
||||
|
||||
// Find out which PWM slice is connected to GPIO 0 (it's slice 0)
|
||||
uint slice_num = pwm_gpio_to_slice_num(0);
|
||||
|
||||
// Set period of 4 cycles (0 to 3 inclusive)
|
||||
pwm_set_wrap(slice_num, 3);
|
||||
// Set channel A output high for one cycle before dropping
|
||||
pwm_set_chan_level(slice_num, PWM_CHAN_A, 1);
|
||||
// Set initial B output high for three cycles before dropping
|
||||
pwm_set_chan_level(slice_num, PWM_CHAN_B, 3);
|
||||
// Set the PWM running
|
||||
pwm_set_enabled(slice_num, true);
|
||||
///end::setup_pwm[]
|
||||
|
||||
// Note we could also use pwm_set_gpio_level(gpio, x) which looks up the
|
||||
// correct slice and channel for a given GPIO.
|
||||
}
|
||||
Reference in New Issue
Block a user