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.
A3921_2p.cpp
- Committer:
- Ryu_25_MIC_512
- Date:
- 2021-07-03
- Revision:
- 0:99d974f5780a
- Child:
- 1:3ea68f4a0556
File content as of revision 0:99d974f5780a:
//********************** // A3921_2p.cpp for mbed // // (C)Copyright 2021 All rights reserved by R.Ihashi //********************** #include "A3921_2p.h" A3921_2p::A3921_2p(PinName pwm_l, PinName phase): PWM_L(pwm_l), PHASE(phase) { reverse = false; duty = 0; period = 0.001; PWM_L.period(period); } A3921_2p::~A3921_2p(){ PWM_L.pulsewidth_us(0); PHASE = 1; } void A3921_2p::SetPeriod(float p){ period = p; PWM_L.period(period); } void A3921_2p::SetEnable(bool mode){ enable = mode; } void A3921_2p::SetReverse(bool mode){ reverse = mode; } void A3921_2p::SetPulseWidth(float t){// -period <= t <= period bool sign = true; if(t > period)t = period; //周期を超えないように制限 else if(t < -period)t = -period;//周期を超えないように制限 duty = int(1000.0 * (t/period));//Duty比を計算 if(t < 0.0f){ //マイナスだったらfalse sign = false; t=-t; } PHASE = reverse ^ sign; //回転方向を指定 PWM_L.pulsewidth((float)enable*t);//パルスを出力 } void A3921_2p::SetPulseWidth_us(int t){ SetPulseWidth((float)t/1000000); } void A3921_2p::SetDuty(int x){ SetPulseWidth((float)x * period / 1000.0f); } int A3921_2p::GetDuty(){ return duty; } int A3921_2p::GetPulseWidth_us(){ return GetPulseWidth() * 1000000; } float A3921_2p::GetPulseWidth(){ float pluse; pluse = (float)duty/1000.0f * period; return fabs(pluse); } float A3921_2p::GetPeriod(){ return period; } bool A3921_2p::GetEnable(){ return enable; } bool A3921_2p::GetReverse(){ return reverse; }