@@ -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_V1)) && HARDWARE_REV < 20
91
+ #if defined(SUPPORT_LIGHTS_SWITCH) && (defined(SUPPORT_XCELL_RT)||defined(SUPPORT_SEMPU)||defined( SUPPORT_SEMPU_V1)) && 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)
136
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
137
137
float wh_human; // human watthours
138
138
#endif
139
139
};
@@ -271,16 +271,19 @@ double torque=0.0; //cyclist's torque in Nm (averaged over one pedal r
271
271
double torque_instant=0.0 ; // cyclist's torque in Nm (live)
272
272
double power_human=0.0 ; // cyclist's power
273
273
double wh_human=0 ;
274
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
274
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)|| defined(SUPPORT_SEMPU)
275
275
int torque_zero=TORQUE_ZERO; // Offset of torque sensor. Adjusted at startup if TORQUE_AUTOZERO option is set
276
276
static volatile boolean analogRead_in_use = false ; // read torque values in interrupt only if no analogRead in process
277
277
static volatile boolean torque_want_calculation = false ; // read torque values in interrupt only if no analogRead in process
278
278
#if HARDWARE_REV<20 && defined(SUPPORT_XCELL_RT)
279
279
const int torquevalues_count=8 ;
280
280
volatile int torquevalues[torquevalues_count]= {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; // stores the 8 torque values per pedal roundtrip
281
- #else
281
+ #elif defined(SUPPORT_SEMPU_V1)
282
282
const int torquevalues_count=16 ;
283
283
volatile int torquevalues[torquevalues_count]= {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; // stores the 16 torque values per pedal roundtrip (Thun) or half roundtrip (Sempu)
284
+ #elif defined(SUPPORT_SEMPU)
285
+ const int torquevalues_count=24 ;
286
+ 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 half roundtrip (Sempu new version)
284
287
#endif
285
288
volatile byte torqueindex=0 ; // index to write next torque value
286
289
volatile boolean readtorque=false ; // true if torque array has been updated -> recalculate in main loop
@@ -473,7 +476,7 @@ digitalWrite(option_pin,HIGH);
473
476
attachInterrupt (0 , pas_change, CHANGE); // attach interrupt for PAS-Sensor
474
477
#endif
475
478
attachInterrupt (1 , speed_change, RISING); // attach interrupt for Wheel-Sensor
476
- #else
479
+ #else // HARDWARE_REV>=20
477
480
bitClear (DDRE,7 ); // configure PE7 as input
478
481
bitSet (PORTE,7 ); // enable pull-up on wheel sensor
479
482
bitSet (EICRB,6 ); // trigger on rising edge INT7 for wheel sensor
@@ -482,18 +485,18 @@ digitalWrite(option_pin,HIGH);
482
485
#ifdef SUPPORT_PAS
483
486
bitClear (DDRE,5 ); // configure PE5 as input
484
487
bitSet (PORTE,5 ); // enable pull-up on PAS sensor
485
- #if !defined(SUPPORT_XCELL_RT) && !defined(SUPPORT_BBS)
488
+ #if !defined(SUPPORT_XCELL_RT) && !defined(SUPPORT_BBS)&& !defined(SUPPORT_SEMPU)
486
489
bitSet (EICRB,2 ); // trigger on any edge INT5 for PAS sensor
487
490
EIMSK |= (1 <<INT5); // turn on interrupt INT5 for PAS sensor
488
491
#else
489
492
bitClear (DDRE,6 ); // configure PE6 as input
490
493
bitSet (PORTE,6 ); // enable pull-up on PAS 2 sensor
491
- bitSet (EICRB,2 ); // trigger on rising edge INT5 for Thun sensor/BBS
492
- bitSet (EICRB,3 ); // trigger on rising edge INT5 for Thun sensor/BBS
493
- bitSet (EICRB,4 ); // trigger on rising edge INT6 for Thun sensor/BBS
494
- bitSet (EICRB,5 ); // trigger on rising edge INT6 for Thun sensor/BBS
494
+ bitSet (EICRB,2 ); // trigger on rising edge INT5 for Thun sensor/BBS/Sempu
495
+ bitSet (EICRB,3 ); // trigger on rising edge INT5 for Thun sensor/BBS/Sempu
496
+ bitSet (EICRB,4 ); // trigger on rising edge INT6 for Thun sensor/BBS/Sempu
497
+ bitSet (EICRB,5 ); // trigger on rising edge INT6 for Thun sensor/BBS/Sempu
495
498
EIMSK |= (1 <<INT5); // turn on interrupt INT5 for PAS sensor
496
- EIMSK |= (1 <<INT6); // turn on interrupt for Thun sensor/BBS
499
+ EIMSK |= (1 <<INT6); // turn on interrupt for Thun sensor/BBS/Sempu
497
500
#endif
498
501
#endif
499
502
#endif
@@ -524,7 +527,7 @@ digitalWrite(option_pin,HIGH);
524
527
poti_stat = map (poti_value_on_startup_in_watts, 0 , curr_power_poti_max, 0 , 1023 );
525
528
#endif
526
529
527
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
530
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)|| defined(SUPPORT_SEMPU)
528
531
#ifdef TORQUE_AUTOZERO
529
532
torque_rezero ();
530
533
#endif
@@ -662,11 +665,11 @@ if (loadcell.is_ready()) //new conversion result from load cell available
662
665
current_display = 0.99 *current_display + 0.01 *current; // averaged current for display
663
666
power=current*voltage;
664
667
665
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
668
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)|| defined(SUPPORT_SEMPU)
666
669
#ifdef SUPPORT_XCELL_RT
667
670
torque_instant=0.49 *(analogRead (option_pin)-torque_zero); // multiplication constant for THUN X-CELL RT is approx. 0.49Nm/count
668
- #else // SEMPU
669
- torque_instant=0.33 *(analogRead (option_pin)-torque_zero); // multiplication constant for SEMPU is approx. 0.33Nm/count
671
+ #else // Sempu
672
+ torque_instant=0.33 *(analogRead (option_pin)-torque_zero); // multiplication constant for SEMPU V1 is approx. 0.33Nm/count
670
673
#endif
671
674
if (readtorque==true )
672
675
{
@@ -684,9 +687,12 @@ if (loadcell.is_ready()) //new conversion result from load cell available
684
687
torque=abs ((torque)*0.03054740957 );
685
688
#endif
686
689
power_human=0.20943951 *cad*torque; // power=2*pi*cadence*torque/60s*2 (*2 because only left side torque is measured by x-cell rt)
687
- #else // SEMPU
690
+ #elif defined(SUPPORT_SEMPU_V1) // SEMPU V1
688
691
torque=abs ((torque)*0.02078055073 ); // torque=sum of torque values/#of torque values*5V/1023 counts/(14.7 mV/Nm)
689
692
power_human=0.10471975512 *cad*torque; // power=2*pi*cadence*torque/60s
693
+ #else // SEMPU
694
+ torque=abs ((torque)*0.01385370049 ); // torque=sum of torque values/#of torque values*5V/1023 counts/(14.7 mV/Nm)
695
+ power_human=0.10471975512 *cad*torque; // power=2*pi*cadence*torque/60s
690
696
#endif
691
697
}
692
698
#endif
@@ -721,7 +727,7 @@ if (loadcell.is_ready()) //new conversion result from load cell available
721
727
wh=variable.wh ;
722
728
km=variable.kilometers ;
723
729
mah=variable.mah ;
724
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
730
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)|| defined(SUPPORT_SEMPU)
725
731
wh_human=variable.wh_human ;
726
732
#endif
727
733
}
@@ -785,7 +791,7 @@ if (loadcell.is_ready()) //new conversion result from load cell available
785
791
power_throttle = throttle_stat / 1023.0 * curr_power_max; // power currently set by throttle
786
792
787
793
#if CONTROL_MODE == CONTROL_MODE_TORQUE // human power control mode
788
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
794
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)|| defined(SUPPORT_SEMPU)
789
795
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
790
796
#ifdef SUPPORT_TORQUE_THROTTLE // we want to trigger throttle just by pedal torque
791
797
if (abs (torque_instant)>torque_throttle_min) // we are above the threshold to trigger throttle
@@ -1066,7 +1072,7 @@ ISR(INT7_vect)
1066
1072
speed_change ();
1067
1073
}
1068
1074
#ifdef SUPPORT_PAS
1069
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_BBS)
1075
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_BBS)|| defined(SUPPORT_SEMPU)
1070
1076
ISR (INT5_vect)
1071
1077
{
1072
1078
pas_change_dual (false );
@@ -1085,7 +1091,7 @@ ISR(INT5_vect)
1085
1091
#endif
1086
1092
1087
1093
#if HARDWARE_REV >= 20
1088
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_BBS)
1094
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_BBS) || defined(SUPPORT_SEMPU)
1089
1095
void pas_change_dual (boolean signal)
1090
1096
{
1091
1097
if (signal)
@@ -1095,13 +1101,15 @@ void pas_change_dual(boolean signal)
1095
1101
pedaling=!bitRead (PINE,6 );
1096
1102
#ifdef SUPPORT_XCELL_RT
1097
1103
cad=7500 /(millis ()-last_pas_event); // 8 pulses per revolution
1098
- #else
1104
+ #elif defined(SUPPORT_BBS)
1099
1105
cad=2500 /(millis ()-last_pas_event); // 24 pulses per revolution
1106
+ #else // Sempu: 48 pulses per revolution
1107
+ cad=1250 /(millis ()-last_pas_event); // 48 pulses per revolution
1100
1108
#endif
1101
1109
last_pas_event = millis ();
1102
1110
}
1103
1111
pedalingbackwards=!pedaling;
1104
- #ifdef SUPPORT_XCELL_RT
1112
+ #if defined( SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU)
1105
1113
if (analogRead_in_use)
1106
1114
{
1107
1115
torque_want_calculation = true ;
@@ -1113,7 +1121,7 @@ void pas_change_dual(boolean signal)
1113
1121
#endif
1114
1122
#endif
1115
1123
1116
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
1124
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1117
1125
void read_current_torque () // this reads the current torque value
1118
1126
{
1119
1127
torquevalues[torqueindex]=analogRead (option_pin)-torque_zero;
@@ -1137,7 +1145,7 @@ void pas_change() //Are we pedaling? PAS Sensor Change--------------------
1137
1145
if (pas_stat)
1138
1146
{
1139
1147
pas_off_time=millis ()-last_pas_event;
1140
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
1148
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1141
1149
if (analogRead_in_use)
1142
1150
torque_want_calculation = true ;
1143
1151
else
@@ -1269,7 +1277,7 @@ void serial_debug(HardwareSerial* localSerial)
1269
1277
localSerial->print (current,1 );
1270
1278
localSerial->print (MY_F (" Power" ));
1271
1279
localSerial->print (power,0 );
1272
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
1280
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1273
1281
localSerial->print (MY_F (" Pedaling" ));
1274
1282
localSerial->print (pedaling);
1275
1283
localSerial->print (MY_F (" Torque" ));
@@ -1325,7 +1333,7 @@ void serial_debug(HardwareSerial* localSerial)
1325
1333
#else
1326
1334
localSerial->print (analogRead_noISR (external_current_in)); Serial.print (MY_F (" ;" ));
1327
1335
#endif
1328
- #ifdef SUPPORT_XCELL_RT
1336
+ #if defined( SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU)
1329
1337
localSerial->print (pedaling); Serial.print (MY_F (" ;" ));
1330
1338
#else
1331
1339
localSerial->print (((int )(100 *(double )pas_on_time/(double )pas_off_time))); Serial.print (MY_F (" ;" ));
@@ -1510,7 +1518,7 @@ void save_eeprom()
1510
1518
#ifdef SUPPORT_BATTERY_CHARGE_COUNTER
1511
1519
variable_new.charge_count =charge_count; // save charge counter
1512
1520
#endif
1513
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
1521
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1514
1522
variable_new.wh_human =wh_human; // save human watthours
1515
1523
#endif
1516
1524
const byte* p_new = (const byte*)(const void *)&variable_new; // pointer to new variables to save
@@ -1581,7 +1589,7 @@ void handle_unused_pins()
1581
1589
1582
1590
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
1583
1591
{
1584
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
1592
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1585
1593
analogRead_in_use = true ; // this prevents analogReads in Interrupt from Thun bracket
1586
1594
if (torque_want_calculation)
1587
1595
{
@@ -1590,7 +1598,7 @@ int analogRead_noISR(uint8_t pin) //this function makes sure that analogRead is
1590
1598
}
1591
1599
#endif
1592
1600
int temp=analogRead (pin);
1593
- #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1)
1601
+ #if defined(SUPPORT_XCELL_RT) || defined(SUPPORT_SEMPU_V1) || defined(SUPPORT_SEMPU)
1594
1602
analogRead_in_use = false ;
1595
1603
#endif
1596
1604
return temp;
0 commit comments