Cleanup: remove superfluous LED pwms
This commit is contained in:
parent
5682479aad
commit
edf697d22b
59
src/main.rs
59
src/main.rs
|
@ -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
|
||||
//! peripheral.
|
||||
//!
|
||||
//! 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.
|
||||
//! Implements a voltage boost regulator. Measures the input and output voltages and output current
|
||||
//! 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.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
@ -46,12 +43,6 @@ mod ext_adc;
|
|||
#[used]
|
||||
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
|
||||
/// if your board has a different frequency
|
||||
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
|
||||
// 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
|
||||
let uart_pins = (
|
||||
|
@ -136,28 +127,19 @@ fn main() -> ! {
|
|||
pwm5.set_top(512);
|
||||
pwm5.enable();
|
||||
|
||||
let pwm6 = &mut pwm_slices.pwm6;
|
||||
pwm6.set_ph_correct();
|
||||
pwm6.enable();
|
||||
let pwm7 = &mut pwm_slices.pwm7;
|
||||
pwm7.set_ph_correct();
|
||||
pwm7.enable();
|
||||
// LED pins
|
||||
let mut pin_led_r = pins.gpio13.into_push_pull_output();
|
||||
let mut pin_led_y = pins.gpio14.into_push_pull_output();
|
||||
let mut pin_led_g = pins.gpio15.into_push_pull_output();
|
||||
|
||||
// Output channel B on PWM4 to GPIO 25
|
||||
let channel1 = &mut pwm6.channel_b;
|
||||
channel1.output_to(pins.gpio13);
|
||||
let channel2 = &mut pwm7.channel_a;
|
||||
channel2.output_to(pins.gpio14);
|
||||
let channel3 = &mut pwm7.channel_b;
|
||||
channel3.output_to(pins.gpio15);
|
||||
pin_led_r.set_high().unwrap();
|
||||
pin_led_y.set_high().unwrap();
|
||||
pin_led_g.set_high().unwrap();
|
||||
|
||||
// set up switch PWM
|
||||
let pwr_switch_ch = &mut pwm5.channel_a;
|
||||
pwr_switch_ch.output_to(pins.gpio10);
|
||||
pwr_switch_ch.set_duty(450);
|
||||
|
||||
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");
|
||||
pwr_switch_ch.set_duty(400);
|
||||
|
||||
// SPI CS pin is controlled by software
|
||||
let mut spi_cs = pins.gpio5.into_push_pull_output();
|
||||
|
@ -180,21 +162,10 @@ fn main() -> ! {
|
|||
spi_cs
|
||||
);
|
||||
|
||||
uart.write_full_blocking(b"Initialization complete!\r\n");
|
||||
|
||||
// Infinite loop, fading LED up and down
|
||||
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];
|
||||
|
||||
(adc_ctrl, adc_value[0]) = adc_ctrl.sample_adc_channel(0);
|
||||
|
|
Loading…
Reference in a new issue