@@ -88,7 +88,7 @@ Time now;
88
88
#error Soft poti is incompatible with throttle auto cruise
89
89
#endif
90
90
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
92
92
#error Software controlled lights switch is not compatible with torque sensor support on FC < 2.0
93
93
#endif
94
94
@@ -133,7 +133,7 @@ struct savings //add variables if you want to store additional values to the e
133
133
#ifdef SUPPORT_BATTERY_CHARGE_COUNTER
134
134
unsigned int charge_count;// battery charge count
135
135
#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)
137
137
float wh_human; // human watthours
138
138
#endif
139
139
};
@@ -256,7 +256,9 @@ int last_throttle_write=0; //last throttle write value
256
256
volatile byte wheel_counter=0 ; // counter for events that should happen once per wheel revolution. only needed if wheel_magnets>1
257
257
volatile unsigned long last_pas_event = millis(); // last change-time of PAS sensor status
258
258
#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
260
262
#else
261
263
#define pas_time 60000 /pas_magnets // conversion factor for pas_time to rpm (cadence)
262
264
#endif
@@ -272,7 +274,7 @@ double torque=0.0; //cyclist's torque in Nm (averaged over one pedal r
272
274
double torque_instant=0.0 ; // cyclist's torque in Nm (live)
273
275
double power_human=0.0 ; // cyclist's power
274
276
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)
276
278
int torque_zero=TORQUE_ZERO; // Offset of torque sensor. Adjusted at startup if TORQUE_AUTOZERO option is set
277
279
static volatile boolean analogRead_in_use = false ; // read torque values in interrupt only if no analogRead in process
278
280
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}
285
287
#elif defined(SUPPORT_SEMPU)
286
288
const int torquevalues_count=24 ;
287
289
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)
288
293
#endif
289
294
volatile byte torqueindex=0 ; // index to write next torque value
290
295
volatile boolean readtorque=false ; // true if torque array has been updated -> recalculate in main loop
@@ -487,7 +492,7 @@ digitalWrite(option_pin,HIGH);
487
492
#ifdef SUPPORT_PAS
488
493
bitClear (DDRE,5 ); // configure PE5 as input
489
494
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
491
496
bitSet (EICRB,2 ); // trigger on any edge INT5 for PAS sensor
492
497
EIMSK |= (1 <<INT5); // turn on interrupt INT5 for PAS sensor
493
498
#else
@@ -529,7 +534,7 @@ digitalWrite(option_pin,HIGH);
529
534
poti_stat = map (poti_value_on_startup_in_watts, 0 , curr_power_poti_max, 0 , 1023 );
530
535
#endif
531
536
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)
533
538
#ifdef TORQUE_AUTOZERO
534
539
torque_rezero ();
535
540
#endif
@@ -668,11 +673,11 @@ if (loadcell.is_ready()) //new conversion result from load cell available
668
673
power=current*voltage;
669
674
power_display = current_display*voltage_display;
670
675
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)
672
677
#ifdef SUPPORT_XCELL_RT
673
678
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
676
681
#endif
677
682
if (readtorque==true )
678
683
{
@@ -693,6 +698,9 @@ if (loadcell.is_ready()) //new conversion result from load cell available
693
698
#elif defined(SUPPORT_SEMPU_V1) // SEMPU V1
694
699
torque=abs ((torque)*0.02078055073 ); // torque=sum of torque values/#of torque values*5V/1023 counts/(14.7 mV/Nm)
695
700
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
696
704
#else // SEMPU
697
705
torque=abs ((torque)*0.01385370049 ); // torque=sum of torque values/#of torque values*5V/1023 counts/(14.7 mV/Nm)
698
706
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
730
738
wh=variable.wh ;
731
739
km=variable.kilometers ;
732
740
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)
734
742
wh_human=variable.wh_human ;
735
743
#endif
736
744
}
@@ -794,7 +802,7 @@ if (loadcell.is_ready()) //new conversion result from load cell available
794
802
power_throttle = throttle_stat / 1023.0 * curr_power_max; // power currently set by throttle
795
803
796
804
#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)
798
806
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
799
807
#ifdef SUPPORT_TORQUE_THROTTLE // we want to trigger throttle just by pedal torque
800
808
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)
1131
1139
#endif
1132
1140
#endif
1133
1141
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)
1135
1143
void read_current_torque () // this reads the current torque value
1136
1144
{
1137
1145
torquevalues[torqueindex]=analogRead (option_pin)-torque_zero;
@@ -1155,7 +1163,7 @@ void pas_change() //Are we pedaling? PAS Sensor Change--------------------
1155
1163
if (pas_stat)
1156
1164
{
1157
1165
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)
1159
1167
if (analogRead_in_use)
1160
1168
torque_want_calculation = true ;
1161
1169
else
@@ -1169,6 +1177,8 @@ void pas_change() //Are we pedaling? PAS Sensor Change--------------------
1169
1177
1170
1178
#ifdef SUPPORT_SEMPU_V1
1171
1179
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!
1172
1182
#else
1173
1183
pas_failtime=pas_failtime+1 ;
1174
1184
double pas_factor=(double )pas_on_time/(double )pas_off_time;
@@ -1287,7 +1297,7 @@ void serial_debug(HardwareSerial* localSerial)
1287
1297
localSerial->print (current,1 );
1288
1298
localSerial->print (MY_F (" Power" ));
1289
1299
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)
1291
1301
localSerial->print (MY_F (" Pedaling" ));
1292
1302
localSerial->print (pedaling);
1293
1303
localSerial->print (MY_F (" Torque" ));
@@ -1528,7 +1538,7 @@ void save_eeprom()
1528
1538
#ifdef SUPPORT_BATTERY_CHARGE_COUNTER
1529
1539
variable_new.charge_count =charge_count; // save charge counter
1530
1540
#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)
1532
1542
variable_new.wh_human =wh_human; // save human watthours
1533
1543
#endif
1534
1544
const byte* p_new = (const byte*)(const void *)&variable_new; // pointer to new variables to save
@@ -1599,7 +1609,7 @@ void handle_unused_pins()
1599
1609
1600
1610
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
1601
1611
{
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)
1603
1613
analogRead_in_use = true ; // this prevents analogReads in Interrupt from Thun bracket
1604
1614
if (torque_want_calculation)
1605
1615
{
@@ -1608,7 +1618,7 @@ int analogRead_noISR(uint8_t pin) //this function makes sure that analogRead is
1608
1618
}
1609
1619
#endif
1610
1620
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)
1612
1622
analogRead_in_use = false ;
1613
1623
#endif
1614
1624
return temp;
0 commit comments