bart594 said:Hi casainho and buba
since some time i'm trying to make 850c compatible with latest alpha firmware. Sadly there is some problem with communication. There is shift from time to time in values like on the pic 1 - the starting byte is in place of message id and the other values are too on incorrect places in array. Pic 2 shows when everything is ok. Basically the values in the rx buffer for motor controller showing randomly? misplaced
I think i tried everything: revert to old communication protocol structure like in stable for lcd and motor controller (sending 6 bytes and message id =8), sending only hardcoded values without variables so no coping between layers is needed for lcd850 , shorting it to only few values. Nothing worked. The only thing that worked partially was increasing sending/receiving interval to 110 ms on lcd but it still not working completely the shift/misplacing is gone for rx array but it is still out of sync because there is no assistance from motor.
I looked at motor controller code for alpha and buba you have changed order when communication is executed:
communications_controller(); // get data to use for motor control and also send new data
ebike_control_motor(); // use received data and sensor input to control motor
on stable it is behind ebike_control_motor
ebike_control_motor();
communications_controller();
But this is still executed in loop every 100 ms so it shouldn't have effect on communication with lcd ?
No, there should be no difference and if it is something is terribly wrong. What is important is the 100 ms timing.
bart594 said:Maybe you you guys have an idea where i should look/check ?
I thought it will be pretty straightforward to adapt the code - just adding few new variables for configuration and copy uart structure from lcd3 but now I'm out of ideas..
I'm using STM Studio to monitor variables live The values that I'm monitoring are on motor controller side
Here is my github with changes
https://github.com/bart594/Color_LCD/
regards
bart594
I am looking at the code now!
------------------------------------
I think something that should be done is to create the riding_mode_controller that is present in the 0.20.0. The riding mode should only change in that function. This is not why you have a problem but it will simplify the debugging.
Code:
void assist_level_state(void)
{
static uint8_t ui8_assist_level_previous = 0xff;
static uint8_t ui8_riding_mode_emtb_prev;
//static uint8_t ui8_var_temp;
static print_number_t assist_level_emtb =
{
.font = &FONT_45X72,
.fore_color = C_ORANGE,
.back_color = C_BCKGROUND_1,
.ui8_previous_digits_array = {255, 255, 255, 255, 255},
.ui8_field_number_of_digits = 1,
.ui8_left_zero_paddig = 0,
};
static print_number_t assist_level =
{
.font = &FONT_45X72,
.fore_color = C_MAIN_1,
.back_color = C_BCKGROUND_1,
.ui8_previous_digits_array = {255, 255, 255, 255, 255},
.ui8_field_number_of_digits = 1,
.ui8_left_zero_paddig = 0,
};
if (m_lcd_vars.ui32_main_screen_draw_static_info)
{
UG_SetBackcolor(C_BCKGROUND_1);
UG_SetForecolor(C_TITLE_1);
UG_FontSelect(&FONT_10X16);
UG_PutString(12, 55, "ASSIST");
}
if (buttons_get_up_click_event() && m_lcd_vars.main_screen_state == MAIN_SCREEN_STATE_MAIN)
{
buttons_clear_all_events();
if (++l3_vars.ui8_assist_level > l3_vars.ui8_number_of_assist_levels)
{
// if eMTB is enabled set to +1
if (1)
{
l3_vars.ui8_assist_level = l3_vars.ui8_number_of_assist_levels + 1;
}
else
{
l3_vars.ui8_assist_level = l3_vars.ui8_number_of_assist_levels;
}
}
}
if (buttons_get_down_click_event() && m_lcd_vars.main_screen_state == MAIN_SCREEN_STATE_MAIN)
{
buttons_clear_all_events();
if (l3_vars.ui8_assist_level > 0) { --l3_vars.ui8_assist_level--; }
}
if ((l3_vars.ui8_assist_level != ui8_assist_level_previous) || m_lcd_vars.ui32_main_screen_draw_static_info)
{
ui8_assist_level_previous = l3_vars.ui8_assist_level;
assist_level.ui32_x_position = 20;
assist_level.ui32_y_position = 81;
assist_level.ui32_number = (uint32_t) l3_vars.ui8_assist_level;
//assist_level.ui8_refresh_all_digits = m_lcd_vars.ui32_main_screen_draw_static_info;
assist_level.ui8_refresh_all_digits = 1;
assist_level_emtb.ui32_x_position = 20;
assist_level_emtb.ui32_y_position = 81;
assist_level_emtb.ui32_number = (uint32_t) l3_vars.ui8_number_of_assist_levels;
//assist_level_emtb.ui8_refresh_all_digits = m_lcd_vars.ui32_main_screen_draw_static_info;
assist_level_emtb.ui8_refresh_all_digits = 1;
if (l3_vars.ui8_assist_level > l3_vars.ui8_number_of_assist_levels) { lcd_print_number(&assist_level_emtb); }
else {lcd_print_number(&assist_level);}
}
}
void riding_mode_controller(void)
{
static uint8_t ui8_walk_assist_state = 0;
static uint8_t ui8_walk_assist_previous;
static uint8_t ui8_riding_mode_previous;
uint32_t ui32_x1;
uint32_t ui32_y1;
uint32_t ui32_x2;
uint32_t ui32_y2;
// reset riding mode
l3_vars.ui8_riding_mode = OFF_MODE;
if ((l3_vars.ui8_assist_level > 0) && (l3_vars.ui8_assist_level < l3_vars.ui8_number_of_assist_levels + 1))
{
// power assist
// torque assist
// cadence assist
}
else if (l3_vars.ui8_assist_level == l3_vars.ui8_number_of_assist_levels + 1)
{
l3_vars.ui8_riding_mode = eMTB_ASSIST_MODE;
}
/*
if (m_lcd_vars.lcd_screen_state == LCD_SCREEN_MAIN && l3_vars.ui8_walk_assist_feature_enabled)
{
if (buttons_get_down_long_click_event())
{
// clear button long down click event
buttons_clear_down_long_click_event();
ui8_walk_assist_state = 1;
}
// if down button is still pressed
if (ui8_walk_assist_state && buttons_get_down_state())
{
l3_vars.ui8_walk_assist = 1;
}
else if(buttons_get_down_state() == 0)
{
ui8_walk_assist_state = 0;
l3_vars.ui8_walk_assist = 0;
}
}
else
{
ui8_walk_assist_state = 0;
l3_vars.ui8_walk_assist = 0;
}
if((l3_vars.ui8_riding_mode < 5) || (l3_vars.ui8_riding_mode > 6)){ui8_riding_mode_previous = l3_vars.ui8_riding_mode;}
if(l3_vars.ui8_walk_assist && (l3_vars.ui8_assist_level > 0) && (l3_vars.ui16_wheel_speed_x10 < WALK_ASSIST_THRESHOLD_SPEED_X10))
{
l3_vars.ui8_riding_mode = WALK_ASSIST_MODE;
}
else if(l3_vars.ui8_walk_assist && (l3_vars.ui16_wheel_speed_x10 > CRUISE_THRESHOLD_SPEED_X10))
{
l3_vars.ui8_riding_mode = CRUISE_MODE;
}
else
{
l3_vars.ui8_riding_mode = ui8_riding_mode_previous;
}
// if previous state was disable, draw
if((l3_vars.ui8_walk_assist != ui8_walk_assist_previous) ||
m_lcd_vars.ui32_main_screen_draw_static_info)
{
ui8_walk_assist_previous = l3_vars.ui8_walk_assist;
if(l3_vars.ui8_walk_assist)
{
UG_SetBackcolor(C_BCKGROUND_2);
UG_SetForecolor(C_MAIN_2);
UG_FontSelect(&SMALL_TEXT_FONT);
ui32_x1 = 190;
ui32_y1 = 10;
UG_PutString(ui32_x1, ui32_y1, "W");
}
else
{
// clear area
// 1 leters
ui32_x1 = 190;
ui32_y1 = 10;
ui32_x2 = ui32_x1 + ((1 * 10) + (1 * 1) + 1);
ui32_y2 = ui32_y1 + 16;
UG_FillFrame(ui32_x1, ui32_y1, ui32_x2, ui32_y2, C_BCKGROUND_2);
}
}
*/
}
This code enables you to remove the walk_assist_state and replace it with the riding_mode_controller. I think you will understand what I have done. The Walk Assist and Cruise are commented for now as it is safer. But by doing this simple change we can be sure that you are always enabling the eMTB mode. There should only be one function that changes the riding modes and this is done for safety and a clear code.
Please note that I do not have the 850C and you need to validate everything.
------------------------------------
EDIT:
Just checked the communication and realized it is going to take some time to look through everything. I believe you when you say that you have tried everything and therefore I do not want to give suboptimal suggestions.
A lot of work is being done on the 850C now together with the SW102. So this will most likely be solved soon. But still... I want to help. Maybe Casainho has an idea that will immediately point you in the right direction.