softwarePWM by ticker, timer

Dependents:   Seeed_Motor_Shield_HelloWorld Official_MedusaIcon Seeed_Motor_Shield adrobo

Committer:
takashikojo
Date:
Thu Apr 05 07:09:39 2012 +0000
Revision:
0:1e86036581bd

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takashikojo 0:1e86036581bd 1 #include "SoftwarePWM.h"
takashikojo 0:1e86036581bd 2 #include "mbed.h"
takashikojo 0:1e86036581bd 3
takashikojo 0:1e86036581bd 4 SoftwarePWM::SoftwarePWM(PinName Pin) : SoftwarePWMPin(Pin) {}
takashikojo 0:1e86036581bd 5
takashikojo 0:1e86036581bd 6 void SoftwarePWM::SetPosition(int Pos) {
takashikojo 0:1e86036581bd 7 Position = Pos;
takashikojo 0:1e86036581bd 8 }
takashikojo 0:1e86036581bd 9
takashikojo 0:1e86036581bd 10 void SoftwarePWM::StartPulse() {
takashikojo 0:1e86036581bd 11 if(Position <= 0) {
takashikojo 0:1e86036581bd 12 SoftwarePWMPin = 0 ;
takashikojo 0:1e86036581bd 13 } else {
takashikojo 0:1e86036581bd 14 SoftwarePWMPin = 1;
takashikojo 0:1e86036581bd 15 PulseStop.attach_us(this, &SoftwarePWM::EndPulse, Position);
takashikojo 0:1e86036581bd 16 }
takashikojo 0:1e86036581bd 17 }
takashikojo 0:1e86036581bd 18
takashikojo 0:1e86036581bd 19 void SoftwarePWM::EndPulse() {
takashikojo 0:1e86036581bd 20 SoftwarePWMPin = 0;
takashikojo 0:1e86036581bd 21 }
takashikojo 0:1e86036581bd 22
takashikojo 0:1e86036581bd 23 void SoftwarePWM::Enable(int StartPos, int Period) {
takashikojo 0:1e86036581bd 24 Position = StartPos;
takashikojo 0:1e86036581bd 25 Pulse.attach_us(this, &SoftwarePWM::StartPulse, Period);
takashikojo 0:1e86036581bd 26 }
takashikojo 0:1e86036581bd 27
takashikojo 0:1e86036581bd 28 void SoftwarePWM::Disable() {
takashikojo 0:1e86036581bd 29 Pulse.detach();
takashikojo 0:1e86036581bd 30 }