encoder and tachometer class for EW3XX single board computer
Diff: EW305sbc.cpp
- Revision:
- 2:6cf351721d86
- Parent:
- 1:b33d4964669b
- Child:
- 4:19ee7eb16605
diff -r b33d4964669b -r 6cf351721d86 EW305sbc.cpp --- a/EW305sbc.cpp Fri Aug 16 19:05:24 2019 +0000 +++ b/EW305sbc.cpp Mon Sep 16 23:34:45 2019 +0000 @@ -14,11 +14,12 @@ speed_ = 0.0; // initial distance countp_ = 0; count_ = 0; + angle_ = 0.0; /** configure the rising edge to start the timer */ updater.attach(callback(this, &EW305sbc::recalc), 0.00625); // 125 Hz, syntax from https://os.mbed.com/forum/mbed/topic/1964/?page=1 wait(.2); //delay at beginning for voltage settle purposes - // initialize channel 1 encoder by + // initialize channel ch_ encoder by LS7366_reset_counter(ch_); LS7366_quad_mode_x4(ch_); LS7366_write_DTR(ch_,0); @@ -29,7 +30,10 @@ { // Read encoder count_ = LS7366_read_counter(ch_); // input is the encoder channel - + + // convert count to angle + angle_ = count_*2.0*3.14159/(4.0*pulsesPerRev_); + // Estimate speed (counts/sec) speed_ = -(count_-countp_)/0.00625*2.0*3.14159/(4.0*pulsesPerRev_); @@ -48,9 +52,10 @@ return speed_; } - - - +float EW305sbc::getAngle(void) +{ + return angle_; +} //---- Function Listing -------------------------------