Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PwmIn.cpp
00001 //mbed Microcontroller Library 00002 //Pulse Width Modulation Input Interface 00003 //Copyright 2010 00004 //Thomas Hamilton 00005 00006 #include "PwmIn.h" 00007 00008 PwmIn::PwmIn(PinName pwi) : InterruptIn(pwi), PeriodMeasurement(0), PulseWidthMeasurement(1) 00009 { 00010 mode(PullDown); 00011 rise(this, &PwmIn::PulseStart); 00012 fall(this, &PwmIn::PulseStop); 00013 start(); 00014 } 00015 00016 float PwmIn::read() 00017 { 00018 return (float)PulseWidthMeasurement / PeriodMeasurement; 00019 } 00020 00021 float PwmIn::period() 00022 { 00023 return (float)PeriodMeasurement / 1000000; 00024 } 00025 00026 int PwmIn::period_ms() 00027 { 00028 return PeriodMeasurement / 1000; 00029 } 00030 00031 int PwmIn::period_us() 00032 { 00033 return PeriodMeasurement; 00034 } 00035 00036 float PwmIn::pulsewidth() 00037 { 00038 return (float)PulseWidthMeasurement / 1000000; 00039 } 00040 00041 int PwmIn::pulsewidth_ms() 00042 { 00043 return PulseWidthMeasurement / 1000; 00044 } 00045 00046 int PwmIn::pulsewidth_us() 00047 { 00048 return PulseWidthMeasurement; 00049 } 00050 00051 void PwmIn::PulseStart() 00052 { 00053 PeriodMeasurement = read_us(); 00054 reset(); 00055 } 00056 00057 void PwmIn::PulseStop() 00058 { 00059 PulseWidthMeasurement = read_us(); 00060 }
Generated on Thu Jul 14 2022 10:11:24 by
1.7.2