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.
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 00004 unsigned int q=0,r=0,s=0,START=8; 00005 00006 PwmOut mypwmA(PA_8); //PWM_OUT 00007 PwmOut mypwmB(PA_9); //PWM_OUT 00008 PwmOut mypwmC(PA_10);//PWM_OUT 00009 00010 00011 DigitalOut EN1(PC_10); 00012 DigitalOut EN2(PC_11); 00013 DigitalOut EN3(PC_12); 00014 00015 InterruptIn HA(PA_15); 00016 InterruptIn HB(PB_3); 00017 InterruptIn HC(PB_10); 00018 00019 unsigned int UP,VP,WP; 00020 AnalogIn V_adc(PC_2); // gaibu Volume 00021 //AnalogIn V_adc(PB_1); //Volume 00022 00023 00024 Serial pc(USBTX,USBRX); 00025 00026 DigitalOut myled(LED1); 00027 00028 float Vr_adc=0.0f; 00029 00030 Timer uT; 00031 float ut1=0,ut2=0,usi=0; 00032 float Speed=0; 00033 00034 void HAH(){ 00035 00036 s=r%2; 00037 if(s==0){ 00038 ut1=uT.read_us(); 00039 r++; 00040 } 00041 00042 if(s==1){ 00043 ut2=uT.read_us(); 00044 r++; 00045 uT.reset(); 00046 } 00047 mypwmA.write(Vr_adc); 00048 mypwmB.write(0); 00049 mypwmC.write(0); 00050 } 00051 00052 void HAL(){ 00053 00054 mypwmA.write(0); 00055 mypwmC.write(0); 00056 00057 } 00058 void HBH(){ 00059 00060 mypwmA.write(0); 00061 mypwmB.write(Vr_adc); 00062 mypwmC.write(0); 00063 } 00064 void HBL(){ 00065 00066 mypwmA.write(0); 00067 mypwmB.write(0); 00068 } 00069 void HCH(){ 00070 00071 mypwmA.write(0); 00072 mypwmB.write(0); 00073 mypwmC.write(Vr_adc); 00074 } 00075 00076 void HCL(){ 00077 mypwmB.write(0); 00078 mypwmC.write(0); 00079 } 00080 00081 int main() { 00082 pc.baud(128000); 00083 00084 EN1=1; 00085 EN2=1; 00086 EN3=1; 00087 00088 mypwmA.period_us(20); // PWM 50KHz 00089 00090 mypwmB.period_us(20); 00091 00092 mypwmC.period_us(20); 00093 00094 00095 while(1) { 00096 00097 Vr_adc=V_adc.read(); 00098 uT.start(); 00099 00100 if((Vr_adc>0.15f)&&(q==0)){ 00101 while(q<50){ 00102 00103 mypwmA.write(0); 00104 mypwmB.write(0.5f); 00105 mypwmC.write(0); 00106 wait_ms(START); 00107 00108 mypwmA.write(0.5f); 00109 mypwmB.write(0); 00110 mypwmC.write(0); 00111 wait_ms(START); 00112 00113 mypwmA.write(0); 00114 mypwmB.write(0); 00115 mypwmC.write(0.5f); 00116 wait_ms(START); 00117 q++; 00118 } 00119 } 00120 00121 HA.rise(&HCH); //HAH 00122 HC.fall(&HBL); //HCL 00123 HB.rise(&HAH); //HBH 00124 HA.fall(&HCL); //HAL 00125 HC.rise(&HBH); //HCH 00126 HB.fall(&HAL); //HBL 00127 // s=0; 00128 if(Vr_adc < 0.1f){ 00129 00130 q=0; 00131 00132 } 00133 00134 usi=abs(ut2-ut1); 00135 Speed=60*(1/(7.0*usi*1E-6)); 00136 pc.printf("%.3f , %.3f \r" ,Speed ,Vr_adc); 00137 //UP=HA; VP=HB; WP=HC; 00138 // pc.printf("%d ,%d ,%d\r" ,UP,VP,WP); 00139 myled = !myled; 00140 00141 } 00142 } 00143
Generated on Thu Jul 14 2022 07:49:27 by
1.7.2