Chris Hills
/
2017_11_28_ELEC347_Coursework
Test
Fork of ELEC347_CourseWork by
main.cpp@0:d39a06ca6bf1, 2017-11-23 (annotated)
- Committer:
- mwthewsey
- Date:
- Thu Nov 23 10:41:18 2017 +0000
- Revision:
- 0:d39a06ca6bf1
- Child:
- 1:b088b771a591
Initial publish. (not working);
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mwthewsey | 0:d39a06ca6bf1 | 1 | #include "mbed.h" |
mwthewsey | 0:d39a06ca6bf1 | 2 | #include "rtos.h" |
mwthewsey | 0:d39a06ca6bf1 | 3 | #include "Filter.hpp" |
mwthewsey | 0:d39a06ca6bf1 | 4 | unsigned short ADC_DATA; |
mwthewsey | 0:d39a06ca6bf1 | 5 | |
mwthewsey | 0:d39a06ca6bf1 | 6 | //Init values for difference equation |
mwthewsey | 0:d39a06ca6bf1 | 7 | //MBED Class Instances follows |
mwthewsey | 0:d39a06ca6bf1 | 8 | DigitalOut SampLED(LED1); //Digital Output (GREEN LED is PB_3, D13 You can use an Oscilloscope on This pin to confirm sample rate) |
mwthewsey | 0:d39a06ca6bf1 | 9 | |
mwthewsey | 0:d39a06ca6bf1 | 10 | AnalogIn Ain(PA_1); //Analog Input (Signal Input 0 to +3 Volts) |
mwthewsey | 0:d39a06ca6bf1 | 11 | AnalogOut Aout(PA_4); //Analog Output (Signal Input 0 to +3 Volts) |
mwthewsey | 0:d39a06ca6bf1 | 12 | |
mwthewsey | 0:d39a06ca6bf1 | 13 | Ticker sample_timer; |
mwthewsey | 0:d39a06ca6bf1 | 14 | Thread T1; |
mwthewsey | 0:d39a06ca6bf1 | 15 | Thread T2; |
mwthewsey | 0:d39a06ca6bf1 | 16 | |
mwthewsey | 0:d39a06ca6bf1 | 17 | FILTER BP_filter(35000,4000,2,2); //Create object of type Filter(Fs,Fo,Boost,Q) |
mwthewsey | 0:d39a06ca6bf1 | 18 | |
mwthewsey | 0:d39a06ca6bf1 | 19 | void sampler(void); |
mwthewsey | 0:d39a06ca6bf1 | 20 | |
mwthewsey | 0:d39a06ca6bf1 | 21 | |
mwthewsey | 0:d39a06ca6bf1 | 22 | int main() |
mwthewsey | 0:d39a06ca6bf1 | 23 | { |
mwthewsey | 0:d39a06ca6bf1 | 24 | |
mwthewsey | 0:d39a06ca6bf1 | 25 | |
mwthewsey | 0:d39a06ca6bf1 | 26 | float sample_rate = (1.0/35000) ; |
mwthewsey | 0:d39a06ca6bf1 | 27 | sample_timer.attach(&sampler,sample_rate); |
mwthewsey | 0:d39a06ca6bf1 | 28 | |
mwthewsey | 0:d39a06ca6bf1 | 29 | |
mwthewsey | 0:d39a06ca6bf1 | 30 | |
mwthewsey | 0:d39a06ca6bf1 | 31 | while(1) { |
mwthewsey | 0:d39a06ca6bf1 | 32 | sleep(); |
mwthewsey | 0:d39a06ca6bf1 | 33 | } |
mwthewsey | 0:d39a06ca6bf1 | 34 | } |
mwthewsey | 0:d39a06ca6bf1 | 35 | |
mwthewsey | 0:d39a06ca6bf1 | 36 | |
mwthewsey | 0:d39a06ca6bf1 | 37 | void sampler(void) |
mwthewsey | 0:d39a06ca6bf1 | 38 | { |
mwthewsey | 0:d39a06ca6bf1 | 39 | |
mwthewsey | 0:d39a06ca6bf1 | 40 | SampLED = 1; //LED Indicates start of sampling |
mwthewsey | 0:d39a06ca6bf1 | 41 | |
mwthewsey | 0:d39a06ca6bf1 | 42 | float input = Ain; |
mwthewsey | 0:d39a06ca6bf1 | 43 | BP_filter.setvalue(input); //Input ADC. N.B. ADC in MBED is 0.0 to 1.0 float!!!!!! |
mwthewsey | 0:d39a06ca6bf1 | 44 | Aout = BP_filter.getvalue(); |
mwthewsey | 0:d39a06ca6bf1 | 45 | |
mwthewsey | 0:d39a06ca6bf1 | 46 | |
mwthewsey | 0:d39a06ca6bf1 | 47 | SampLED = 0; //LED Indicates end of sampling |
mwthewsey | 0:d39a06ca6bf1 | 48 | } |
mwthewsey | 0:d39a06ca6bf1 | 49 |