Interface class for the Max Botix ultrasonic range finder model 1210. It includes input methods for PWM, Analog, and Serial. A PwmIn class was created to allow the PWM input to be read. Now includes automatic range update via interrupts.

Dependencies:   mbed

Committer:
Blaze513
Date:
Sat Aug 28 07:59:29 2010 +0000
Revision:
4:a615b75d4126
Parent:
3:05183e50a923

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Blaze513 2:997b4057c879 1 //mbed Microcontroller Library
Blaze513 2:997b4057c879 2 //Pulse Width Modulation Input Interface
Blaze513 2:997b4057c879 3 //Copyright 2010
Blaze513 2:997b4057c879 4 //Thomas Hamilton
Blaze513 2:997b4057c879 5
Blaze513 0:3d969e0b4ca0 6 #include "PwmIn.h"
Blaze513 0:3d969e0b4ca0 7
Blaze513 0:3d969e0b4ca0 8 PwmIn::PwmIn(PinName pwi) : InterruptIn(pwi), PeriodMeasurement(0), PulseWidthMeasurement(1)
Blaze513 0:3d969e0b4ca0 9 {
Blaze513 3:05183e50a923 10 mode(PullDown);
Blaze513 3:05183e50a923 11 rise(this, &PwmIn::PulseStart);
Blaze513 3:05183e50a923 12 fall(this, &PwmIn::PulseStop);
Blaze513 3:05183e50a923 13 start();
Blaze513 0:3d969e0b4ca0 14 }
Blaze513 0:3d969e0b4ca0 15
Blaze513 0:3d969e0b4ca0 16 float PwmIn::read()
Blaze513 0:3d969e0b4ca0 17 {
Blaze513 0:3d969e0b4ca0 18 return (float)PulseWidthMeasurement / PeriodMeasurement;
Blaze513 0:3d969e0b4ca0 19 }
Blaze513 0:3d969e0b4ca0 20
Blaze513 0:3d969e0b4ca0 21 float PwmIn::period()
Blaze513 0:3d969e0b4ca0 22 {
Blaze513 0:3d969e0b4ca0 23 return (float)PeriodMeasurement / 1000000;
Blaze513 0:3d969e0b4ca0 24 }
Blaze513 0:3d969e0b4ca0 25
Blaze513 0:3d969e0b4ca0 26 int PwmIn::period_ms()
Blaze513 0:3d969e0b4ca0 27 {
Blaze513 0:3d969e0b4ca0 28 return PeriodMeasurement / 1000;
Blaze513 0:3d969e0b4ca0 29 }
Blaze513 0:3d969e0b4ca0 30
Blaze513 0:3d969e0b4ca0 31 int PwmIn::period_us()
Blaze513 0:3d969e0b4ca0 32 {
Blaze513 0:3d969e0b4ca0 33 return PeriodMeasurement;
Blaze513 0:3d969e0b4ca0 34 }
Blaze513 0:3d969e0b4ca0 35
Blaze513 0:3d969e0b4ca0 36 float PwmIn::pulsewidth()
Blaze513 0:3d969e0b4ca0 37 {
Blaze513 0:3d969e0b4ca0 38 return (float)PulseWidthMeasurement / 1000000;
Blaze513 0:3d969e0b4ca0 39 }
Blaze513 0:3d969e0b4ca0 40
Blaze513 0:3d969e0b4ca0 41 int PwmIn::pulsewidth_ms()
Blaze513 0:3d969e0b4ca0 42 {
Blaze513 0:3d969e0b4ca0 43 return PulseWidthMeasurement / 1000;
Blaze513 0:3d969e0b4ca0 44 }
Blaze513 0:3d969e0b4ca0 45
Blaze513 0:3d969e0b4ca0 46 int PwmIn::pulsewidth_us()
Blaze513 0:3d969e0b4ca0 47 {
Blaze513 0:3d969e0b4ca0 48 return PulseWidthMeasurement;
Blaze513 0:3d969e0b4ca0 49 }
Blaze513 0:3d969e0b4ca0 50
Blaze513 0:3d969e0b4ca0 51 void PwmIn::PulseStart()
Blaze513 0:3d969e0b4ca0 52 {
Blaze513 0:3d969e0b4ca0 53 PeriodMeasurement = read_us();
Blaze513 0:3d969e0b4ca0 54 reset();
Blaze513 0:3d969e0b4ca0 55 }
Blaze513 0:3d969e0b4ca0 56
Blaze513 0:3d969e0b4ca0 57 void PwmIn::PulseStop()
Blaze513 0:3d969e0b4ca0 58 {
Blaze513 0:3d969e0b4ca0 59 PulseWidthMeasurement = read_us();
Blaze513 0:3d969e0b4ca0 60 }