scooter / Mbed 2 deprecated Scooter-uC-Programm

Dependencies:   mbed

Committer:
drummer
Date:
Tue Jun 23 10:53:51 2015 +0000
Revision:
13:565aa2c6bd3d
Parent:
12:bad33209d1bb
OneTrueBraceStyle

Who changed what in which revision?

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