Skip to content

Commit e7b52ed

Browse files
author
jenkie
committed
Support multiple wheel magnets
Set your number of wheel magnets in config.h via wheel_magnets
1 parent 22b75b6 commit e7b52ed

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Arduino_Pedelec_Controller/Arduino_Pedelec_Controller.ino

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ byte short_writetime_counter = 0; //Counter for fast-loop
216216
#endif
217217
volatile unsigned long last_wheel_time = millis(); //last time of wheel sensor change 0->1
218218
volatile unsigned long wheel_time = 65535; //time for one revolution of the wheel
219+
volatile byte wheel_counter=0; //counter for events that should happen once per wheel revolution. only needed if wheel_magnets>1
219220
volatile unsigned long last_pas_event = millis(); //last change-time of PAS sensor status
220221
#define pas_time 60000/pas_magnets //conversion factor for pas_time to rpm (cadence)
221222
volatile boolean pedaling = false; //pedaling? (in forward direction!)
@@ -976,19 +977,22 @@ void speed_change() //Wheel Sensor Change------------------------------------
976977

977978
//Speed and Km
978979
if (last_wheel_time>(millis()-50)) return; //debouncing reed-sensor
979-
++odo;
980-
wheel_time=millis()-last_wheel_time;
980+
wheel_counter++;
981+
wheel_time=(millis()-last_wheel_time)*wheel_magnets;
981982
spd = (spd+3600*wheel_circumference/wheel_time)/2; //a bit of averaging for smoother speed-cutoff
982-
if (spd<100)
983-
{km=km+wheel_circumference/1000.0;}
984-
else
985-
{spd=0;}
983+
984+
if (wheel_counter>(wheel_magnets-1)) //wheel has made one complete revolution
985+
{
986+
wheel_counter=0;
987+
km=km+wheel_circumference/1000.0;
988+
++odo;
986989
#if defined(SUPPORT_BMP085) || defined(SUPPORT_DSPC01)
987990
//slope-stuff start-------------------------------
988-
slope=0.98*slope+2*(altitude-last_altitude)/wheel_circumference;
989-
last_altitude=altitude;
991+
slope=0.98*slope+2*(altitude-last_altitude)/wheel_circumference;
992+
last_altitude=altitude;
990993
//slope-stuff end---------------------------------
991-
#endif
994+
#endif
995+
}
992996
last_wheel_time=millis();
993997
}
994998

Arduino_Pedelec_Controller/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const float vmax=42.0; //Battery voltage when fully charged
160160
const float vcutoff=33.0; //cutoff voltage in V;
161161
const float vemergency_shutdown = 28.0; //emergency power off situation to save the battery from undervoltage
162162
const float wheel_circumference = 2.202; //wheel circumference in m
163+
const byte wheel_magnets=1; //configure your number of wheel magnets here
163164
const int spd_max1=22; //speed cutoff start in Km/h
164165
const int spd_max2=25; //speed cutoff stop (0W) in Km/h
165166
const int power_max=500; //Maximum power in W (throttle mode)

0 commit comments

Comments
 (0)