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.
Fork of SymbitronValves by
main.cpp
00001 #include "mbed.h" 00002 //#include "FastPWM.h" 00003 #include "HIDScope.h" 00004 //#include "tsi_sensor.h" 00005 00006 #define V1_CLOSE D2 00007 #define V1_OPEN D3 00008 #define V2_CLOSE D4 00009 #define V2_OPEN D5 00010 #define V3_CLOSE A2 00011 #define V3_OPEN A3 00012 #define V4_CLOSE D8 00013 #define V4_OPEN D9 00014 00015 #define TSI_A PTB16 00016 #define TSI_B PTB17 00017 00018 #define PRESSURE PTB0 00019 #define EXTERNAL_SETPOINT PTC2 00020 00021 DigitalOut v1open(V1_OPEN); 00022 DigitalOut v1close(V1_CLOSE); 00023 HIDScope scope(3); 00024 AnalogIn ain_setpoint(EXTERNAL_SETPOINT); 00025 AnalogIn pressure(PRESSURE); 00026 //TSIAnalogSlider slider(TSI_A, TSI_B, 100); 00027 Ticker valvetick; 00028 00029 volatile float setpoint1; 00030 00031 static inline float getPressure_Pa(void) 00032 { 00033 float voltage = pressure.read()*3.3; 00034 float sensor_output = (voltage*2)-0.2;//offset compensation 00035 float press = sensor_output*10000; //gain (might be off a bit. Is the full scale range without the offset? then it would be ~9000). 00036 return press; 00037 } 00038 00039 void valvecontrol(void) 00040 { 00041 static uint16_t usbcounter = 0; 00042 float meas = getPressure_Pa(); 00043 setpoint1= ain_setpoint.read()*60000; 00044 if(setpoint1 - meas >2500) { 00045 v1close = 0; 00046 v1open = 1; 00047 } else if (meas - setpoint1 > 2500) { 00048 v1close = 1; 00049 v1open = 0; 00050 } else 00051 v1open = v1close = 0; 00052 usbcounter++; 00053 if(usbcounter == 20) { 00054 scope.set(0,setpoint1); 00055 scope.set(1,meas); 00056 scope.set(2,meas); 00057 scope.send(); 00058 usbcounter = 0; 00059 } 00060 } 00061 00062 int main() 00063 { 00064 valvetick.attach(valvecontrol,0.001); 00065 while(1) { 00066 //setpoint1 = ain_setpoint.read()*30000; 00067 //scope.set(2,ain_setpoint); 00068 wait(0.1); 00069 } 00070 }
Generated on Sat Jul 23 2022 02:17:57 by
1.7.2
