Francisco Guerra
/
SymbitronValves
Amplitude Modulation Code
Fork of SymbitronValves by
main.cpp
- Committer:
- vsluiter
- Date:
- 2015-07-03
- Revision:
- 6:d73f051400ee
- Parent:
- 5:4772ef79675f
- Child:
- 7:9f6dfd88cd18
File content as of revision 6:d73f051400ee:
#include "mbed.h" //#include "FastPWM.h" #include "HIDScope.h" //#include "tsi_sensor.h" #define V1_CLOSE D2 #define V1_OPEN D3 #define V2_CLOSE D4 #define V2_OPEN D5 #define V3_CLOSE A2 #define V3_OPEN A3 #define V4_CLOSE D8 #define V4_OPEN D9 #define TSI_A PTB16 #define TSI_B PTB17 #define PRESSURE A0 #define EXTERNAL_SETPOINT A4 DigitalOut v1open(V1_OPEN); DigitalOut v1close(V1_CLOSE); HIDScope scope(3); AnalogIn pressure(PRESSURE); AnalogIn ain_setpoint(EXTERNAL_SETPOINT); //TSIAnalogSlider slider(TSI_A, TSI_B, 100); Ticker valvetick; float setpoint1 = 0; float getPressure_Pa(void) { float voltage = pressure.read()*3.3; float sensor_output = (voltage*2)-0.2;//offset compensation float pressure = sensor_output*10000; //gain (might be off a bit. Is the full scale range without the offset? then it would be ~9000). return pressure; } void valvecontrol(void) { static uint16_t usbcounter = 0; float meas = getPressure_Pa(); if(setpoint1 - meas >2000) { v1close = 0; v1open = 1; } else if (meas - setpoint1 > 2000) { v1close = 1; v1open = 0; } else v1open = v1close = 0; usbcounter++; if(usbcounter == 200) { scope.set(0,setpoint1); scope.set(1,meas); scope.set(2,meas); scope.send(); usbcounter = 0; } } int main() { valvetick.attach(valvecontrol,0.0001); while(1) { setpoint1 = ain_setpoint.read()*30000; wait(0.05); } }