scooter / Mbed 2 deprecated Scooter-uC-Programm

Dependencies:   mbed

Committer:
thorb3n
Date:
Tue Jun 23 10:49:55 2015 +0000
Revision:
12:bad33209d1bb
Parent:
11:7dfdb8074992
Child:
13:565aa2c6bd3d
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thorb3n 1:4d1b3fffabd5 1 #include "mbed.h"
thorb3n 12:bad33209d1bb 2 const int mosfet1_resistence = 100; // Resistence in Ohm
thorb3n 12:bad33209d1bb 3 AnalogIn voltage0(A0); // Edit Pin-Port for the battery-voltage measurement
thorb3n 7:ed9a83df000a 4 AnalogIn voltage1(A1); // Edit Pin-Port for the throttle-voltage measurement
thorb3n 7:ed9a83df000a 5 AnalogIn voltage2(A2); // Edit Pin-Port for the capacitor-voltage measurement
thorb3n 8:fb6cb712eb52 6 DigitalIn breaksensor(PA_5); //Edit Pin-Port for the breaksensor measurement!
thorb3n 11:7dfdb8074992 7 AnalogIn voltage3(A3); // Pin-Port for voltage before Mosfet1
thorb3n 11:7dfdb8074992 8 AnalogIn voltage4(A4); // Pin-Port for voltage after Mosfet2
thorb3n 12:bad33209d1bb 9 Timer timer2; // Timer for Capacity-Measurement
thorb3n 12:bad33209d1bb 10 float accu_voltage(){
thorb3n 7:ed9a83df000a 11
thorb3n 7:ed9a83df000a 12 float meas0;
thorb3n 7:ed9a83df000a 13 meas0 = voltage0.read(); // read adc value
thorb3n 7:ed9a83df000a 14 return meas0; // return value
scooter_project 5:d213c03872fe 15 }
scooter_project 5:d213c03872fe 16
thorb3n 7:ed9a83df000a 17 float hall_umrechnung(){
thorb3n 7:ed9a83df000a 18 float meas0;
thorb3n 8:fb6cb712eb52 19 meas0 = voltage1.read() - 0.27; // read adc and rearange the voltage_value,because its 0.27 when the throttle is off
thorb3n 7:ed9a83df000a 20
thorb3n 7:ed9a83df000a 21 if(meas0 < 0){ // meas0 isnt allowed to be <0 because its sets the pulsewidht of the pwm
thorb3n 7:ed9a83df000a 22 meas0 = 0;
thorb3n 7:ed9a83df000a 23 }
scooter_project 5:d213c03872fe 24
thorb3n 7:ed9a83df000a 25 meas0 = meas0*2; // creates values between 0 and 1
thorb3n 7:ed9a83df000a 26
thorb3n 7:ed9a83df000a 27 if(meas0 > 1){ // meas0 isnt allowed to be >1 because its sets the pulsewidth of the pwm
scooter_project 5:d213c03872fe 28 meas0 = 1;
thorb3n 7:ed9a83df000a 29 }
thorb3n 7:ed9a83df000a 30
thorb3n 7:ed9a83df000a 31 return meas0; // return value
scooter_project 5:d213c03872fe 32 }
thorb3n 12:bad33209d1bb 33 //-------------Code für Bremsenergierückgewinnung---------------
thorb3n 12:bad33209d1bb 34 /*
thorb3n 7:ed9a83df000a 35 float Capacitor_Voltage(){
thorb3n 7:ed9a83df000a 36
thorb3n 7:ed9a83df000a 37 float meas0;
thorb3n 8:fb6cb712eb52 38 meas0 = voltage2.read(); //read adc value
thorb3n 7:ed9a83df000a 39 return meas0; // return value
thorb3n 7:ed9a83df000a 40 }
thorb3n 12:bad33209d1bb 41 */ //-----------------------------------------------------------
thorb3n 8:fb6cb712eb52 42 int break_value(){
thorb3n 8:fb6cb712eb52 43 int break_value;
thorb3n 8:fb6cb712eb52 44 break_value = breaksensor.read(); // read breaksensor value(1/0)
thorb3n 8:fb6cb712eb52 45 return break_value; // return value
thorb3n 11:7dfdb8074992 46 }
thorb3n 12:bad33209d1bb 47 float battery_charge(){
thorb3n 12:bad33209d1bb 48 Timer timer2;
thorb3n 12:bad33209d1bb 49 float battery_charge,current;
thorb3n 12:bad33209d1bb 50 int time,voltage_before,voltage_after;
thorb3n 12:bad33209d1bb 51 voltage_before = voltage3.read()*12.0; // voltage in V
thorb3n 12:bad33209d1bb 52 voltage_after = voltage4.read()*12.0; // voltage in V
thorb3n 12:bad33209d1bb 53 current = (voltage_before - voltage_after)/(mosfet1_resistence); // current in A
thorb3n 12:bad33209d1bb 54 timer2.start(); // Timer start
thorb3n 12:bad33209d1bb 55 time = timer2.read_ms();
thorb3n 12:bad33209d1bb 56 while(time < 10){ // loop to get 0.01s delay
thorb3n 12:bad33209d1bb 57 ;
thorb3n 12:bad33209d1bb 58 }
thorb3n 12:bad33209d1bb 59 timer2.stop();
thorb3n 12:bad33209d1bb 60 timer2.reset();
thorb3n 12:bad33209d1bb 61
thorb3n 12:bad33209d1bb 62 battery_charge = battery_charge - current*0.01;
thorb3n 12:bad33209d1bb 63 return battery_charge;
thorb3n 12:bad33209d1bb 64 }