now using a mosfet, no "center"
This commit is contained in:
parent
782fd891a1
commit
6192627e25
1 changed files with 10 additions and 11 deletions
|
@ -99,9 +99,9 @@ async fn main(spawner: Spawner) {
|
|||
let mut drive_pwm = Pwm::new_output_ab(p.PWM_SLICE1, p.PIN_18, p.PIN_19, d.clone());
|
||||
|
||||
let mut f: pwm::Config = Default::default();
|
||||
f.divider = 40.into();
|
||||
f.top = 62500; // 20ms
|
||||
f.compare_b = 4687; // 1.5ms
|
||||
f.divider = 1.into(); // no reason to slow down, this is going right into a mosfet
|
||||
f.top = u16::MAX;
|
||||
f.compare_b = 0;
|
||||
let flip_pwm = Pwm::new_output_b(p.PWM_SLICE0, p.PIN_17, f.clone());
|
||||
|
||||
let sda = p.PIN_20;
|
||||
|
@ -295,14 +295,13 @@ async fn main(spawner: Spawner) {
|
|||
}
|
||||
}
|
||||
|
||||
/// -1 to 1
|
||||
/// 0 to 1
|
||||
fn calc_speed(speed: f32) -> u16 {
|
||||
const COUNTS_PER_MS: f32 = 3125.;
|
||||
let speed = speed.clamp(-1., 1.);
|
||||
let speed = speed.clamp(0., 1.);
|
||||
|
||||
let ms = (speed/2.0)+1.5;
|
||||
let speed = speed * u16::MAX as f32;
|
||||
|
||||
(COUNTS_PER_MS * ms) as u16
|
||||
speed as u16
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -361,8 +360,8 @@ fn handle_cam(cam: &mut Pwm, state: &mut CamState, limit: &Input) {
|
|||
|
||||
|
||||
let mut f: pwm::Config = Default::default();
|
||||
f.divider = 40.into();
|
||||
f.top = 62500; // 20ms
|
||||
f.compare_b = calc_speed(-speed); // 1.5ms
|
||||
f.divider = 1.into();
|
||||
f.top = u16::MAX;
|
||||
f.compare_b = calc_speed(speed);
|
||||
cam.set_config(&f);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue