Cleanup: remove superfluous LED pwms

This commit is contained in:
Thomas Kolb 2023-01-07 17:25:04 +01:00
parent 5682479aad
commit edf697d22b

View file

@ -1,11 +1,8 @@
//! # PWM Blink Example //! # Firmware for the handcrank project.
//! //!
//! If you have an LED connected to pin 25, it will fade the LED using the PWM //! Implements a voltage boost regulator. Measures the input and output voltages and output current
//! peripheral. //! using an external ADC connected via SPI to pins GP2 to GP5. The switching transistor is
//! //! controlled directly via a PWM signal on pin GP10.
//! It may need to be adapted to your particular board layout and/or pin assignment.
//!
//! See the `Cargo.toml` file for Copyright and license details.
#![no_std] #![no_std]
#![no_main] #![no_main]
@ -46,12 +43,6 @@ mod ext_adc;
#[used] #[used]
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H; pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H;
/// The minimum PWM value (i.e. LED brightness) we want
const LOW: u16 = 0;
/// The maximum PWM value (i.e. LED brightness) we want
const HIGH: u16 = 25000;
/// External high-speed crystal on the Raspberry Pi Pico board is 12 MHz. Adjust /// External high-speed crystal on the Raspberry Pi Pico board is 12 MHz. Adjust
/// if your board has a different frequency /// if your board has a different frequency
const XTAL_FREQ_HZ: u32 = 12_000_000u32; const XTAL_FREQ_HZ: u32 = 12_000_000u32;
@ -109,7 +100,7 @@ fn main() -> ! {
// The delay object lets us wait for specified amounts of time (in // The delay object lets us wait for specified amounts of time (in
// milliseconds) // milliseconds)
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); //let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
// UART // UART
let uart_pins = ( let uart_pins = (
@ -136,28 +127,19 @@ fn main() -> ! {
pwm5.set_top(512); pwm5.set_top(512);
pwm5.enable(); pwm5.enable();
let pwm6 = &mut pwm_slices.pwm6; // LED pins
pwm6.set_ph_correct(); let mut pin_led_r = pins.gpio13.into_push_pull_output();
pwm6.enable(); let mut pin_led_y = pins.gpio14.into_push_pull_output();
let pwm7 = &mut pwm_slices.pwm7; let mut pin_led_g = pins.gpio15.into_push_pull_output();
pwm7.set_ph_correct();
pwm7.enable();
// Output channel B on PWM4 to GPIO 25 pin_led_r.set_high().unwrap();
let channel1 = &mut pwm6.channel_b; pin_led_y.set_high().unwrap();
channel1.output_to(pins.gpio13); pin_led_g.set_high().unwrap();
let channel2 = &mut pwm7.channel_a;
channel2.output_to(pins.gpio14);
let channel3 = &mut pwm7.channel_b;
channel3.output_to(pins.gpio15);
// set up switch PWM
let pwr_switch_ch = &mut pwm5.channel_a; let pwr_switch_ch = &mut pwm5.channel_a;
pwr_switch_ch.output_to(pins.gpio10); pwr_switch_ch.output_to(pins.gpio10);
pwr_switch_ch.set_duty(450); pwr_switch_ch.set_duty(400);
let mut ch_val: [u16; 3] = [LOW, LOW + (HIGH - LOW) / 3, LOW + 2 * (HIGH - LOW) / 3];
uart.write_full_blocking(b"Initialization complete!\r\n");
// SPI CS pin is controlled by software // SPI CS pin is controlled by software
let mut spi_cs = pins.gpio5.into_push_pull_output(); let mut spi_cs = pins.gpio5.into_push_pull_output();
@ -180,21 +162,10 @@ fn main() -> ! {
spi_cs spi_cs
); );
uart.write_full_blocking(b"Initialization complete!\r\n");
// Infinite loop, fading LED up and down // Infinite loop, fading LED up and down
loop { loop {
for i in 0..ch_val.len() {
ch_val[i] += 1;
if ch_val[i] > HIGH {
ch_val[i] -= HIGH - LOW;
}
}
channel1.set_duty(ch_val[0]);
channel2.set_duty(ch_val[1]);
channel3.set_duty(ch_val[2]);
delay.delay_us(50);
let mut adc_value: [u16; 4] = [0; 4]; let mut adc_value: [u16; 4] = [0; 4];
(adc_ctrl, adc_value[0]) = adc_ctrl.sample_adc_channel(0); (adc_ctrl, adc_value[0]) = adc_ctrl.sample_adc_channel(0);