Skip to content

Commit

Permalink
Refactor into different files and update example(still not compiling …
Browse files Browse the repository at this point in the history
…by far)
  • Loading branch information
usbalbin committed Sep 25, 2022
1 parent 0eb109d commit e9e7eb0
Show file tree
Hide file tree
Showing 6 changed files with 645 additions and 918 deletions.
28 changes: 15 additions & 13 deletions examples/mcpwm-simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,24 @@ fn main() -> anyhow::Result<()> {
println!("Configuring MCPWM");

let peripherals = Peripherals::take().unwrap();
let config = OperatorConfig::default().frequency(25.kHz());
let mcpwm = Mcpwm::new(peripherals.mcpwm0.mcpwm)?;
let mut operator = Operator::new(
peripherals.mcpwm0.operator0,
&mcpwm,
&config,
peripherals.pins.gpio4,
peripherals.pins.gpio5,
)?;
let timer_config = TimerConfig::default().frequency(25.kHz());
let operator_config = OperatorConfig::default();
let timer = Mcpwm::new(peripherals.mcpwm0.timer, timer_config)?;

println!("Starting duty-cycle loop");
let timer = timer.into_connection()
.attatch_operator0(
peripherals.mcpwm0.operator0,
operator_config,
peripherals.pins.gpio4,
peripherals.pins.gpio5,
)?;

let (timer, operator, _, _) = timer.split();

for x in (0..10000u16).cycle() {
let duty = f32::from(x) * 0.01;
println!("Starting duty-cycle loop");

if x % 100 == 0 {
for duty in (0..timer.get_top_value()).cycle() {
if duty % 100 == 0 {
println!("Duty {}%", x / 100);
}

Expand Down
Loading

0 comments on commit e9e7eb0

Please sign in to comment.