You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to configure the 4th channel to trigger timer1 3 complementary output and adc.
macro! pwm_4_channels_with_3_complementary_outputs() macro, the point I'm stuck on is that I don't know how to access the 4th channel.
I don't want to connect to the GPIO pin to which the 4th channel is connected
#![deny(unsafe_code)]
#![no_main]
#![no_std]
// Halt on panic
use panic_halt as _;
use cortex_m;
use cortex_m_rt::entry;
use stm32f0xx_hal as hal;
use hal::{delay::Delay, pac::{self, TIM1}, prelude::*, pwm, adc};
#[entry]
fn main() -> ! {
if let Some(mut dp) = pac::Peripherals::take() {
// Set up the system clock.
let mut rcc = dp.RCC.configure().sysclk(8.mhz()).freeze(&mut dp.FLASH);
let gpioa = dp.GPIOA.split(&mut rcc);
let gpiob = dp.GPIOB.split(&mut rcc);
let channels = cortex_m::interrupt::free(move |cs| {
(
gpioa.pa8.into_alternate_af2(cs), // on TIM1_CH1
gpiob.pb13.into_alternate_af2(cs), // on TIM1_CH1N
gpioa.pa9.into_alternate_af2(cs), // on TIM1_CH2
gpiob.pb14.into_alternate_af2(cs), // on TIM1_CH2N
gpioa.pa10.into_alternate_af2(cs), // on TIM1_CH3
gpiob.pb15.into_alternate_af2(cs), // on TIM1_CH3N
)
});
let pwm = pwm::tim1(dp.TIM1, channels, &mut rcc, 20u32.khz());
let (mut pwm_c_h, mut pwm_c_l, mut pwm_b_h, mut pwm_b_l, mut pwm_a_h, mut pwm_a_l) = pwm;
let max_duty = pwm_c_h.get_max_duty();
pwm_c_h.set_duty(max_duty / 2);
pwm_c_h.enable();
pwm_c_l.enable();
pwm_b_h.set_duty(max_duty / 2);
pwm_b_h.enable();
pwm_b_l.enable();
pwm_a_h.set_duty(max_duty / 2);
pwm_a_h.enable();
pwm_a_l.enable();
// simple duty sweep
if let Some(cp) = cortex_m::Peripherals::take() {
let mut delay = Delay::new(cp.SYST, &rcc);
let steps = 100;
loop {
for i in 0..steps {
pwm_c_h.set_duty(max_duty / steps * i);
pwm_b_h.set_duty(max_duty / steps * i);
pwm_a_h.set_duty(max_duty / steps * i);
delay.delay_ms(30u16);
}
for i in (1..steps).rev() {
pwm_c_h.set_duty(max_duty / steps * i);
pwm_b_h.set_duty(max_duty / steps * i);
pwm_a_h.set_duty(max_duty / steps * i);
delay.delay_ms(30u16);
}
}
}
}
// something went wrong when acquiring peripheral access
loop {
cortex_m::asm::nop();
}
}
The text was updated successfully, but these errors were encountered:
I need to configure the 4th channel to trigger timer1 3 complementary output and adc.
macro! pwm_4_channels_with_3_complementary_outputs() macro, the point I'm stuck on is that I don't know how to access the 4th channel.
I don't want to connect to the GPIO pin to which the 4th channel is connected
#![deny(unsafe_code)]
#![no_main]
#![no_std]
// Halt on panic
use panic_halt as _;
use cortex_m;
use cortex_m_rt::entry;
use stm32f0xx_hal as hal;
use hal::{delay::Delay, pac::{self, TIM1}, prelude::*, pwm, adc};
#[entry]
fn main() -> ! {
if let Some(mut dp) = pac::Peripherals::take() {
// Set up the system clock.
let mut rcc = dp.RCC.configure().sysclk(8.mhz()).freeze(&mut dp.FLASH);
}
The text was updated successfully, but these errors were encountered: