A program to monitor some parameters for a motor
Dependencies: mbed-dev BufferSerial
Thanks to David Lowe for https://developer.mbed.org/users/gregeric/code/Nucleo_Hello_Encoder/ which I adapted for the use of TIM2 32bit timer as an encoder reader on the Nucleo L432KC board.
Diff: main.cpp
- Revision:
- 19:51075c725004
- Parent:
- 18:1ef20c13693c
- Child:
- 20:f62feecc8334
--- a/main.cpp Thu Jun 15 18:16:15 2017 +0000 +++ b/main.cpp Sat Jun 17 21:04:42 2017 +0000 @@ -284,19 +284,21 @@ led1 = 0; } -//Function to compute the average of ADC readings +//Function to compute the average of 1000 ADC readings +//Current intensity measurement should be as precise +//as possible, the time delay introduced my multiplying +//the readings is tolerable for this project float ADC_read(AnalogIn adc) { float Voltage; float Voltage_total = 0.0; // Voltage is summed then averaged - for (int i=0; i<100; i++) { // do 100 readings + for (int i=0; i<1000; i++) { // do 1000 readings Voltage = adc.read(); Voltage_total = Voltage_total+ Voltage; - //wait_us(10); } - Voltage = Voltage_total/100.f; + Voltage = Voltage_total/1000.f; return Voltage; } @@ -321,7 +323,7 @@ event.rise(&atint); //Set serial baud rate - raspi.baud(115200); + raspi.baud(921600); //Attach functin to call for serial interrupt event //The wait() function ensures that not false serial RX @@ -380,7 +382,7 @@ } printf("\n"); - wait(0.08); + wait(0.005); } } \ No newline at end of file