extract timer configuration
This commit is contained in:
parent
bc920907bd
commit
1f098f70b8
2 changed files with 13 additions and 10 deletions
14
src/main.rs
14
src/main.rs
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
mod servo;
|
mod servo;
|
||||||
use servo::Servo;
|
use servo::{configure_timer_one, Servo};
|
||||||
|
|
||||||
#[arduino_hal::entry]
|
#[arduino_hal::entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
|
@ -11,15 +11,9 @@ fn main() -> ! {
|
||||||
let pins = arduino_hal::pins!(dp);
|
let pins = arduino_hal::pins!(dp);
|
||||||
|
|
||||||
// configure timer for servos
|
// configure timer for servos
|
||||||
pins.d9.into_output();
|
pins.d9.into_output(); // carriage
|
||||||
pins.d10.into_output();
|
pins.d10.into_output(); // claw
|
||||||
let tc1 = dp.TC1; // 250kHz
|
let (carriage, claw) = configure_timer_one(&dp.TC1);
|
||||||
tc1.icr1.write(|w| w.bits(4999)); // 250kHz/5000 = 50Hz
|
|
||||||
tc1.tccr1a.write(|w| w.wgm1().bits(0b10).com1a().match_clear());
|
|
||||||
tc1.tccr1b.write(|w| w.wgm1().bits(0b11).cs1().prescale_64());
|
|
||||||
|
|
||||||
let carriage = &tc1.ocr1a; // pin 9
|
|
||||||
let claw = &tc1.ocr1b; // pin 10
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
carriage.set_speed(1.0);
|
carriage.set_speed(1.0);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use arduino_hal::pac::tc1::OCR1B;
|
use arduino_hal::pac::tc1::OCR1B;
|
||||||
use arduino_hal::pac::tc1::OCR1A;
|
use arduino_hal::pac::tc1::OCR1A;
|
||||||
|
use arduino_hal::pac::TC1;
|
||||||
|
|
||||||
const MIN: u16 = 100; // *4us = .4ms
|
const MIN: u16 = 100; // *4us = .4ms
|
||||||
const MAX: u16 = 700; // *4us = 2.8ms
|
const MAX: u16 = 700; // *4us = 2.8ms
|
||||||
|
@ -34,6 +35,14 @@ impl Servo for OCR1B { // pin 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn configure_timer_one(timer: &TC1) -> (&OCR1A, &OCR1B) {
|
||||||
|
timer.icr1.write(|w| w.bits(4999)); // 250kHz/5000 = 50Hz
|
||||||
|
timer.tccr1a.write(|w| w.wgm1().bits(0b10).com1a().match_clear());
|
||||||
|
timer.tccr1b.write(|w| w.wgm1().bits(0b11).cs1().prescale_64());
|
||||||
|
|
||||||
|
(&timer.ocr1a, &timer.ocr1b)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
// unit tests don't run on avr-hal-template projects, could be due to target rules, could be
|
// unit tests don't run on avr-hal-template projects, could be due to target rules, could be
|
||||||
|
|
Loading…
Reference in a new issue