![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Non-variable (TESTEDandWORKING)
Fork of ELEC347_Coursework by
main.cpp@1:b088b771a591, 2017-11-28 (annotated)
- Committer:
- mwthewsey
- Date:
- Tue Nov 28 09:41:07 2017 +0000
- Revision:
- 1:b088b771a591
- Parent:
- 0:d39a06ca6bf1
- Child:
- 2:f6e49378dd8a
First working version;
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 | |
mwthewsey | 1:b088b771a591 | 50 | https://os.mbed.com/users/thomasmorris/code/ELEC347_CourseWork/ |