Skip to content

Commit

Permalink
Merge pull request stylesuxx#56 from giacomo892/giacomo892_clean
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
AlkaMotors authored Aug 7, 2021
2 parents e1a9f82 + 8bfb754 commit be28260
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 93 deletions.
1 change: 0 additions & 1 deletion Inc/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern int adjusted_input;
extern int newinput;
extern char inputSet;
extern char dshot;
extern char oneshot125;
extern char servoPwm;
extern uint32_t gcr[];
extern int armed_count_threshold;
Expand Down
1 change: 0 additions & 1 deletion Mcu/f051/Inc/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ extern int adjusted_input;
extern int newinput;
extern char inputSet;
extern char dshot;
extern char oneshot125;
extern char servoPwm;
extern uint32_t gcr[];
extern int armed_count_threshold;
Expand Down
4 changes: 0 additions & 4 deletions Mcu/f051/Src/IO.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ void detectInput(){
smallestnumber = 20000;
average_signal_pulse = 0;
dshot = 0;
// proshot = 0;
// multishot = 0;
// oneshot42 = 0;
oneshot125 = 0;
servoPwm = 0;
int lastnumber = dma_buffer[0];

Expand Down
1 change: 0 additions & 1 deletion Mcu/f350/Inc/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ extern int input;
extern int newinput;
extern char inputSet;
extern char dshot;
extern char oneshot125;
extern char servoPwm;
extern uint32_t gcr[];
extern int armed_count_threshold;
Expand Down
4 changes: 0 additions & 4 deletions Mcu/f350/Src/IO.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ void sendDshotDma(){
void detectInput(){
smallestnumber = 20000;
dshot = 0;
// proshot = 0;
// multishot = 0;
// oneshot42 = 0;
// oneshot125 = 0;
servoPwm = 0;
int lastnumber = dma_buffer[0];
for ( int j = 1 ; j < 31; j++){
Expand Down
11 changes: 0 additions & 11 deletions Mcu/g071/Src/IO.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ void sendDshotDma(){
void detectInput(){
smallestnumber = 20000;
dshot = 0;
// proshot = 0;
// multishot = 0;
// oneshot42 = 0;
// oneshot125 = 0;
servoPwm = 0;
int lastnumber = dma_buffer[0];
for ( int j = 1 ; j < 31; j++){
Expand Down Expand Up @@ -138,16 +134,9 @@ void detectInput(){
buffersize = 32;
}
if ((smallestnumber > 100 )&&(smallestnumber < 400)){
// multishot = 1;
armed_count_threshold = 1000;
buffersize = 4;
}
// if ((smallestnumber > 2000 )&&(smallestnumber < 3000)){
// oneshot42 = 1;
// }
//// if ((smallestnumber > 3000 )&&(smallestnumber < 7000)){
//// oneshot125 = 1;
//// }
if (smallestnumber > 1500){
servoPwm = 1;
ic_timer_prescaler=63;
Expand Down
3 changes: 0 additions & 3 deletions Src/dshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,3 @@ for (int i = 15; i >= 9 ; i--){


}



2 changes: 1 addition & 1 deletion Src/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ void delayMillis(uint32_t millis){
}
UTILITY_TIMER->PSC = CPU_FREQUENCY_MHZ; // back to micros
LL_TIM_GenerateEvent_UPDATE(UTILITY_TIMER);
}
}
67 changes: 23 additions & 44 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
*-- increase max change a low rpm x10
*-- set low limit of throttle ramp to a lower point and increase upper range
*-- change desync event from full restart to just lower throttle.
*1.64
* --added startup check for continuous high signal, reboot to enter bootloader.
*-- added brake on stop from eeprom
Expand Down Expand Up @@ -152,13 +152,11 @@ uint16_t desired_angle = 90;
uint32_t MCU_Id = 0;
uint32_t REV_Id = 0;

uint16_t loop_time = 0;
uint16_t last_loop_time = 0;
uint16_t armed_timeout_count;

uint8_t desync_happened = 0;
char maximum_throttle_change_ramp = 1;
char sine_mode_changeover_thottle_level = 5;
char sine_mode_changeover_thottle_level = 5;
char drag_brake_strength = 10;

char crawler_mode = 0; // no longer used //
Expand Down Expand Up @@ -209,7 +207,6 @@ char startup_boost = 35;
char stall_protection = 0;
char reversing_dead_band = 1;

uint16_t oneKhz_timer = 0;
int checkcount = 0;
uint16_t low_pin_count = 0;

Expand Down Expand Up @@ -299,9 +296,7 @@ int filter_level = 5;
int running = 0;
int advance = 0;
int advancedivisor = 6;
//int START_ARR=800;
char rising = 1;
int count = 0;

////Space Vector PWM ////////////////
//const int pwmSin[] ={128, 132, 136, 140, 143, 147, 151, 155, 159, 162, 166, 170, 174, 178, 181, 185, 189, 192, 196, 200, 203, 207, 211, 214, 218, 221, 225, 228, 232, 235, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 253, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 253, 252, 252, 251, 250, 250, 249, 248, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 253, 253, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 253, 253, 253, 252, 252, 251, 250, 250, 249, 248, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 235, 232, 228, 225, 221, 218, 214, 211, 207, 203, 200, 196, 192, 189, 185, 181, 178, 174, 170, 166, 162, 159, 155, 151, 147, 143, 140, 136, 132, 128, 124, 120, 116, 113, 109, 105, 101, 97, 94, 90, 86, 82, 78, 75, 71, 67, 64, 60, 56, 53, 49, 45, 42, 38, 35, 31, 28, 24, 21, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 8, 7, 6, 6, 5, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 24, 28, 31, 35, 38, 42, 45, 49, 53, 56, 60, 64, 67, 71, 75, 78, 82, 86, 90, 94, 97, 101, 105, 109, 113, 116, 120, 124};
Expand Down Expand Up @@ -381,10 +376,6 @@ int input = 0;
int newinput =0;
char inputSet = 0;
char dshot = 0;
char proshot = 0;
char multishot = 0;
char oneshot42 = 0;
char oneshot125 = 0;
char servoPwm = 0;
int zero_crosses;

Expand Down Expand Up @@ -489,7 +480,7 @@ void loadEEpromSettings(){

motor_kv = (eepromBuffer[26] * 40) + 20;
motor_poles = eepromBuffer[27];

if(eepromBuffer[28] == 0x01){
brake_on_stop = 1;
}else{
Expand Down Expand Up @@ -531,7 +522,7 @@ void loadEEpromSettings(){
RC_CAR_REVERSE = 0;
}
if(eepromBuffer[39] == 0x01){
#ifdef HAS_HALL_SENSORS
#ifdef HAS_HALL_SENSORS
USE_HALL_SENSOR = 1;
#else
USE_HALL_SENSOR = 0;
Expand All @@ -553,7 +544,7 @@ void loadEEpromSettings(){
}
low_rpm_level = motor_kv / 200 / (16 / motor_poles);
high_rpm_level = (40 + (motor_kv / 100)) / (16/motor_poles);

if(!comp_pwm){
bi_direction = 0;
}
Expand Down Expand Up @@ -852,10 +843,10 @@ if(!armed){
}
}
if (RC_CAR_REVERSE && prop_brake_active) {
#ifndef PWM_ENABLE_BRIDGE
#ifndef PWM_ENABLE_BRIDGE
duty_cycle = getAbsDif(1000, newinput) + 1000;
proportionalBrake();
#endif
#endif
}


Expand All @@ -866,8 +857,8 @@ if(!armed){
zero_crosses = 0;
bad_count = 0;
if(brake_on_stop){
if(!use_sin_start){
duty_cycle = 1980 + drag_brake_strength*2;
if(!use_sin_start){
duty_cycle = 1980 + drag_brake_strength*2;
proportionalBrake();
prop_brake_active = 1;
}
Expand Down Expand Up @@ -986,7 +977,7 @@ if(desync_check && zero_crosses > 10){
last_average_interval = average_interval;
}
if(send_telemetry){
#ifdef USE_SERIAL_TELEMETRY
#ifdef USE_SERIAL_TELEMETRY
makeTelemPackage(degrees_celsius,
battery_voltage,
actual_current,
Expand Down Expand Up @@ -1122,8 +1113,6 @@ int main(void)

initCorePeripherals();

//

LL_TIM_CC_EnableChannel(TIM1, LL_TIM_CHANNEL_CH1);
LL_TIM_CC_EnableChannel(TIM1, LL_TIM_CHANNEL_CH2);
LL_TIM_CC_EnableChannel(TIM1, LL_TIM_CHANNEL_CH3);
Expand All @@ -1140,7 +1129,7 @@ int main(void)
#ifdef USE_ADC_INPUT

#else
//
//
LL_TIM_CC_EnableChannel(IC_TIMER_REGISTER, IC_TIMER_CHANNEL); // input capture and output compare
LL_TIM_EnableCounter(IC_TIMER_REGISTER);
#endif
Expand Down Expand Up @@ -1177,7 +1166,7 @@ int main(void)

__IO uint32_t wait_loop_index = 0;
/* Enable comparator */

LL_COMP_Enable(MAIN_COMP);

wait_loop_index = ((LL_COMP_DELAY_STARTUP_US * (SystemCoreClock / (100000 * 2))) / 10);
Expand Down Expand Up @@ -1256,11 +1245,11 @@ if (GIMBAL_MODE){
checkForHighSignal(); // will reboot if signal line is high for 10ms
receiveDshotDma();
#endif

#ifdef MCU_F051
MCU_Id = DBGMCU->IDCODE &= 0xFFF;
REV_Id = DBGMCU->IDCODE >> 16;

if(REV_Id >= 4096){
temperature_offset = 0;
}else{
Expand All @@ -1271,17 +1260,7 @@ if (GIMBAL_MODE){
{

LL_IWDG_ReloadCounter(IWDG);
count++;

// if(count>10){
//
//
// if(loop_time>=last_loop_time){
// loop_time = (10*loop_time + (UTILITY_TIMER->CNT - last_loop_time))/11;
// }
// last_loop_time = UTILITY_TIMER->CNT;
// count = 0;
// }
adc_counter++;
if(adc_counter>100){ // for testing adc and telemetry
ADC_raw_temp = ADC_raw_temp - (temperature_offset);
Expand Down Expand Up @@ -1318,8 +1297,8 @@ LL_IWDG_ReloadCounter(IWDG);
}
#endif
}


#ifdef USE_ADC_INPUT

signaltimeout = 0;
Expand All @@ -1330,8 +1309,8 @@ if(newinput > 2000){
}
#endif
stuckcounter = 0;
if (bi_direction == 1 && proshot == 0 && dshot == 0){

if (bi_direction == 1 && dshot == 0){
if(RC_CAR_REVERSE){
if (newinput > (1000 + (servo_dead_band<<1))) {
if (forward == dir_reversed) {
Expand Down Expand Up @@ -1402,7 +1381,7 @@ if(newinput > 2000){
brushed_direction_set = 0;
}
}
}else if ((proshot || dshot) && bi_direction) {
}else if (dshot && bi_direction) {
if (newinput > 1047) {

if (forward == dir_reversed) {
Expand Down Expand Up @@ -1631,7 +1610,7 @@ if (old_routine && running){
if(input > 48 && armed){

if (input > 48 && input < 137){// sine wave stepper

maskPhaseInterrupts();
allpwm();
advanceincrement();
Expand All @@ -1652,7 +1631,7 @@ if(input > 48 && armed){
old_routine = 1;
commutation_interval = 9000;
average_interval = 9000;
last_average_interval = average_interval;
last_average_interval = average_interval;
// minimum_duty_cycle = ;
INTERVAL_TIMER->CNT = 9000;
zero_crosses = 0;
Expand All @@ -1666,7 +1645,7 @@ if(input > 48 && armed){

}else{
if(brake_on_stop){
duty_cycle = 1980 + drag_brake_strength*2;
duty_cycle = 1980 + drag_brake_strength*2;
adjusted_duty_cycle = TIMER1_MAX_ARR - ((duty_cycle * tim1_arr)/TIMER1_MAX_ARR)+1;
TIM1->ARR = tim1_arr;
TIM1->CCR1 = adjusted_duty_cycle;
Expand Down Expand Up @@ -1706,7 +1685,7 @@ void Error_Handler(void)
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
Expand Down
21 changes: 0 additions & 21 deletions Src/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,3 @@ if(!armed){
}
}
}





















4 changes: 2 additions & 2 deletions f051makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CC = $(ARM_SDK_PREFIX)gcc
CP = $(ARM_SDK_PREFIX)objcopy
MCU := -mcpu=cortex-m0 -mthumb
LDSCRIPT := Mcu/f051/STM32F051K6TX_FLASH.ld
LIBS := -lc -lm -lnosys
LIBS := -lc -lm -lnosys
LDFLAGS := -specs=nano.specs -T$(LDSCRIPT) $(LIBS) -Wl,--gc-sections -Wl,--print-memory-usage
MAIN_SRC_DIR := Src
SRC_DIR := Mcu/f051/Startup \
Expand All @@ -15,7 +15,7 @@ INCLUDES := \
-IMcu/f051/Inc \
-IMcu/f051/Drivers/STM32F0xx_HAL_Driver/Inc \
-IMcu/f051/Drivers/CMSIS/Include \
-IMcu/f051/Drivers/CMSIS/Device/ST/STM32F0xx/Include
-IMcu/f051/Drivers/CMSIS/Device/ST/STM32F0xx/Include
VALUES := \
-DUSE_MAKE \
-DHSE_VALUE=8000000 \
Expand Down

0 comments on commit be28260

Please sign in to comment.