Francisco Guerra
/
SymbitronValves
Amplitude Modulation Code
Fork of SymbitronValves by
Diff: main.cpp
- Revision:
- 7:9f6dfd88cd18
- Parent:
- 6:d73f051400ee
- Child:
- 8:89be5a6807f0
--- a/main.cpp Fri Jul 03 10:20:08 2015 +0000 +++ b/main.cpp Fri Jul 03 12:59:11 2015 +0000 @@ -15,31 +15,32 @@ #define TSI_A PTB16 #define TSI_B PTB17 -#define PRESSURE A0 -#define EXTERNAL_SETPOINT A4 +#define PRESSURE PTB0 +#define EXTERNAL_SETPOINT PTC2 DigitalOut v1open(V1_OPEN); DigitalOut v1close(V1_CLOSE); HIDScope scope(3); +AnalogIn ain_setpoint(EXTERNAL_SETPOINT); AnalogIn pressure(PRESSURE); -AnalogIn ain_setpoint(EXTERNAL_SETPOINT); //TSIAnalogSlider slider(TSI_A, TSI_B, 100); Ticker valvetick; -float setpoint1 = 0; +volatile float setpoint1; -float getPressure_Pa(void) +static inline 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; + float press = sensor_output*10000; //gain (might be off a bit. Is the full scale range without the offset? then it would be ~9000). + return press; } void valvecontrol(void) { static uint16_t usbcounter = 0; float meas = getPressure_Pa(); + setpoint1= ain_setpoint.read()*50000; if(setpoint1 - meas >2000) { v1close = 0; v1open = 1; @@ -49,7 +50,7 @@ } else v1open = v1close = 0; usbcounter++; - if(usbcounter == 200) { + if(usbcounter == 20) { scope.set(0,setpoint1); scope.set(1,meas); scope.set(2,meas); @@ -60,9 +61,10 @@ int main() { - valvetick.attach(valvecontrol,0.0001); + valvetick.attach(valvecontrol,0.001); while(1) { - setpoint1 = ain_setpoint.read()*30000; - wait(0.05); + //setpoint1 = ain_setpoint.read()*30000; + //scope.set(2,ain_setpoint); + wait(0.1); } }