Skip to content

Commit db3f342

Browse files
author
Jens Kießling
committed
Added support for Erider T9 bottom bracket
1 parent 5fcac02 commit db3f342

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

Arduino_Pedelec_Controller/Arduino_Pedelec_Controller.ino

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Time now;
8888
#error Soft poti is incompatible with throttle auto cruise
8989
#endif
9090

91-
#if defined(SUPPORT_LIGHTS_SWITCH) && (defined(SUPPORT_XCELL_RT)||defined(SUPPORT_SEMPU)||defined(SUPPORT_SEMPU_V1)) && HARDWARE_REV < 20
91+
#if defined(SUPPORT_LIGHTS_SWITCH) && (defined(SUPPORT_XCELL_RT)||defined(SUPPORT_SEMPU)||defined(SUPPORT_SEMPU_V1)||defined(SUPPORT_T9)) && HARDWARE_REV < 20
9292
#error Software controlled lights switch is not compatible with torque sensor support on FC < 2.0
9393
#endif
9494

@@ -133,7 +133,7 @@ struct savings //add variables if you want to store additional values to the e
133133
#ifdef SUPPORT_BATTERY_CHARGE_COUNTER
134134
unsigned int charge_count;//battery charge count
135135
#endif
136-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
136+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
137137
float wh_human; //human watthours
138138
#endif
139139
};
@@ -256,7 +256,9 @@ int last_throttle_write=0; //last throttle write value
256256
volatile byte wheel_counter=0; //counter for events that should happen once per wheel revolution. only needed if wheel_magnets>1
257257
volatile unsigned long last_pas_event = millis(); //last change-time of PAS sensor status
258258
#ifdef SUPPORT_SEMPU_V1
259-
#define pas_time 1875 //conversion factor for pas_time to rpm (cadence)
259+
#define pas_time 1875 //conversion factor for pas_time to rpm (cadence), 32 Pulses
260+
#elif defined(SUPPORT_T9)
261+
#define pas_time 3333 //conversion factor for pas_time to rpm (cadence), 18 Pulses
260262
#else
261263
#define pas_time 60000/pas_magnets //conversion factor for pas_time to rpm (cadence)
262264
#endif
@@ -272,7 +274,7 @@ double torque=0.0; //cyclist's torque in Nm (averaged over one pedal r
272274
double torque_instant=0.0; //cyclist's torque in Nm (live)
273275
double power_human=0.0; //cyclist's power
274276
double wh_human=0;
275-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
277+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
276278
int torque_zero=TORQUE_ZERO; //Offset of torque sensor. Adjusted at startup if TORQUE_AUTOZERO option is set
277279
static volatile boolean analogRead_in_use = false; //read torque values in interrupt only if no analogRead in process
278280
static volatile boolean torque_want_calculation = false; //read torque values in interrupt only if no analogRead in process
@@ -285,6 +287,9 @@ volatile int torquevalues[torquevalues_count]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
285287
#elif defined(SUPPORT_SEMPU)
286288
const int torquevalues_count=24;
287289
volatile int torquevalues[torquevalues_count]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //stores the 24 torque values per pedal roundtrip (Sempu new version)
290+
#elif defined(SUPPORT_T9)
291+
const int torquevalues_count=18;
292+
volatile int torquevalues[torquevalues_count]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //stores the 18 torque values per half roundtrip (T9)
288293
#endif
289294
volatile byte torqueindex=0; //index to write next torque value
290295
volatile boolean readtorque=false; //true if torque array has been updated -> recalculate in main loop
@@ -487,7 +492,7 @@ digitalWrite(option_pin,HIGH);
487492
#ifdef SUPPORT_PAS
488493
bitClear(DDRE,5); //configure PE5 as input
489494
bitSet(PORTE,5); //enable pull-up on PAS sensor
490-
#if !defined(SUPPORT_XCELL_RT) && !defined(SUPPORT_BBS) && !defined(SUPPORT_SEMPU)
495+
#if !defined(SUPPORT_XCELL_RT) && !defined(SUPPORT_BBS) && !defined(SUPPORT_SEMPU) //add second interrupt for two-signal-pas-sensors
491496
bitSet(EICRB,2); //trigger on any edge INT5 for PAS sensor
492497
EIMSK |= (1<<INT5); //turn on interrupt INT5 for PAS sensor
493498
#else
@@ -529,7 +534,7 @@ digitalWrite(option_pin,HIGH);
529534
poti_stat = map(poti_value_on_startup_in_watts, 0, curr_power_poti_max, 0, 1023);
530535
#endif
531536

532-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
537+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) ||defined(SUPPORT_T9)
533538
#ifdef TORQUE_AUTOZERO
534539
torque_rezero();
535540
#endif
@@ -668,11 +673,11 @@ if (loadcell.is_ready()) //new conversion result from load cell available
668673
power=current*voltage;
669674
power_display = current_display*voltage_display;
670675

671-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
676+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
672677
#ifdef SUPPORT_XCELL_RT
673678
torque_instant=0.49*(analogRead(option_pin)-torque_zero); //multiplication constant for THUN X-CELL RT is approx. 0.49Nm/count
674-
#else //Sempu
675-
torque_instant=0.33*(analogRead(option_pin)-torque_zero); //multiplication constant for SEMPU V1 is approx. 0.33Nm/count
679+
#else //Sempu and T9
680+
torque_instant=0.33*(analogRead(option_pin)-torque_zero); //multiplication constant for SEMPU and T9 is approx. 0.33Nm/count
676681
#endif
677682
if (readtorque==true)
678683
{
@@ -693,6 +698,9 @@ if (loadcell.is_ready()) //new conversion result from load cell available
693698
#elif defined(SUPPORT_SEMPU_V1) //SEMPU V1
694699
torque=abs((torque)*0.02078055073); //torque=sum of torque values/#of torque values*5V/1023 counts/(14.7 mV/Nm)
695700
power_human=0.10471975512*cad*torque; //power=2*pi*cadence*torque/60s
701+
#elif defined(SUPPORT_T9) //Erider T9
702+
torque=abs((torque)*0.01847160065); //torque=sum of torque values/#of torque values*5V/1023 counts/(14.7 mV/Nm)
703+
power_human=0.10471975512*cad*torque; //power=2*pi*cadence*torque/60s
696704
#else //SEMPU
697705
torque=abs((torque)*0.01385370049); //torque=sum of torque values/#of torque values*5V/1023 counts/(14.7 mV/Nm)
698706
power_human=0.10471975512*cad*torque; //power=2*pi*cadence*torque/60s
@@ -730,7 +738,7 @@ if (loadcell.is_ready()) //new conversion result from load cell available
730738
wh=variable.wh;
731739
km=variable.kilometers;
732740
mah=variable.mah;
733-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
741+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
734742
wh_human=variable.wh_human;
735743
#endif
736744
}
@@ -794,7 +802,7 @@ if (loadcell.is_ready()) //new conversion result from load cell available
794802
power_throttle = throttle_stat / 1023.0 * curr_power_max; //power currently set by throttle
795803

796804
#if CONTROL_MODE == CONTROL_MODE_TORQUE //human power control mode
797-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
805+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
798806
power_poti = poti_stat/102300.0* curr_power_poti_max*power_human*(1+spd/20.0); //power_poti_max is in this control mode interpreted as percentage. Example: power_poti_max=200 means; motor power = 200% of human power
799807
#ifdef SUPPORT_TORQUE_THROTTLE //we want to trigger throttle just by pedal torque
800808
if (abs(torque_instant)>torque_throttle_min) //we are above the threshold to trigger throttle
@@ -1131,7 +1139,7 @@ void pas_change_dual(boolean signal)
11311139
#endif
11321140
#endif
11331141

1134-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1142+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
11351143
void read_current_torque() //this reads the current torque value
11361144
{
11371145
torquevalues[torqueindex]=analogRead(option_pin)-torque_zero;
@@ -1155,7 +1163,7 @@ void pas_change() //Are we pedaling? PAS Sensor Change--------------------
11551163
if (pas_stat)
11561164
{
11571165
pas_off_time=millis()-last_pas_event;
1158-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1166+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
11591167
if (analogRead_in_use)
11601168
torque_want_calculation = true;
11611169
else
@@ -1169,6 +1177,8 @@ void pas_change() //Are we pedaling? PAS Sensor Change--------------------
11691177

11701178
#ifdef SUPPORT_SEMPU_V1
11711179
pedaling=bitRead(PINE,6); //read direction pin of pas sensor and set pedaling to true
1180+
#elif defined(SUPPORT_T9)
1181+
pedaling=true; //no direction pin, set pedaling to true!
11721182
#else
11731183
pas_failtime=pas_failtime+1;
11741184
double pas_factor=(double)pas_on_time/(double)pas_off_time;
@@ -1287,7 +1297,7 @@ void serial_debug(HardwareSerial* localSerial)
12871297
localSerial->print(current,1);
12881298
localSerial->print(MY_F(" Power"));
12891299
localSerial->print(power,0);
1290-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1300+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
12911301
localSerial->print(MY_F(" Pedaling"));
12921302
localSerial->print(pedaling);
12931303
localSerial->print(MY_F(" Torque"));
@@ -1528,7 +1538,7 @@ void save_eeprom()
15281538
#ifdef SUPPORT_BATTERY_CHARGE_COUNTER
15291539
variable_new.charge_count=charge_count; //save charge counter
15301540
#endif
1531-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1541+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
15321542
variable_new.wh_human=wh_human; //save human watthours
15331543
#endif
15341544
const byte* p_new = (const byte*)(const void*)&variable_new; //pointer to new variables to save
@@ -1599,7 +1609,7 @@ void handle_unused_pins()
15991609

16001610
int analogRead_noISR(uint8_t pin) //this function makes sure that analogRead is never used in interrupt. only important for X-Cell RT bottom brackets
16011611
{
1602-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1612+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
16031613
analogRead_in_use = true; //this prevents analogReads in Interrupt from Thun bracket
16041614
if (torque_want_calculation)
16051615
{
@@ -1608,7 +1618,7 @@ int analogRead_noISR(uint8_t pin) //this function makes sure that analogRead is
16081618
}
16091619
#endif
16101620
int temp=analogRead(pin);
1611-
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1621+
#if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU) || defined(SUPPORT_T9)
16121622
analogRead_in_use = false;
16131623
#endif
16141624
return temp;

Arduino_Pedelec_Controller/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ const int fixed_throttle_in_watts = 250; //number of watts to set as thr
143143
#define BBS_GEARCHANGEPAUSE 2000 //powerless time in milliseconds to allow gear change
144144
// #define SUPPORT_XCELL_RT //uncomment if X-CELL RT connected. FC1.4: pas_factor_min=0.2, pas_factor_max=0.5. FC1.5: pas_factor_min=0.5, pas_factor_max=1.5. pas_magnets=8
145145
// #define SUPPORT_SEMPU_V1 //uncomment if you have a Sempu torque sensor, old type with one direction wire and one pas wire
146-
//#define SUPPORT_SEMPU //uncomment if you have a Sempu torque sensor, new type with two pas wires
146+
// #define SUPPORT_SEMPU //uncomment if you have a Sempu torque sensor, new type with two pas wires
147+
// #define SUPPORT_T9 //uncomment if you have a n Erider T9 bottom bracked with one torque wire and one speed wire (4 pins in total)
147148
// #define SUPPORT_TORQUE_THROTTLE
148149
// #define SUPPORT_HRMI //uncomment if polar heart-rate monitor interface connected to i2c port
149150
#define SUPPORT_BRAKE //uncomment if brake switch connected

0 commit comments

Comments
 (0)