casainho
10 GW
- Joined
- Feb 14, 2011
- Messages
- 6,058
I am just preparing a structure of the firmware and want to put it as master. As for now, I have the Kunteng LCD working (just send speed) and the main loop seems it is finished and is clean. We can now grow the firmware but (try) maintain the structure. I think should be easier for you now, and I will try to put your code back (LCD + PAS | Torque sensor) but you are also free to do it.stancecoke said:I'm sad, you have thrown away all my ifdefs for the different ride modes...casainho said:Stancecoke,
See my clean main loop now.![]()
I will concentrate on the start up procedure for my motor with 6 steps now. (And perhaps I'll understand what is happening ...)
See here the main loop:
Code:
while (1)
{
ui16_TIM2_counter = TIM2_GetCounter ();
if ((ui16_TIM2_counter - ui16_motor_controller_counter) > 100) // every 100ms
{
ui16_motor_controller_counter = ui16_TIM2_counter;
motor_controller_high_level ();
continue;
}
ui16_TIM2_counter = TIM2_GetCounter ();
if ((ui16_TIM2_counter - ui16_communications_controller_counter) > 150) // every 100ms
{
ui16_communications_controller_counter = ui16_TIM2_counter;
communications_controller ();
continue;
}
ui16_TIM2_counter = TIM2_GetCounter ();
if ((ui16_TIM2_counter - ui16_throttle_pas_torque_sensor_controller_counter) > 20) // every 20ms
{
ui16_throttle_pas_torque_sensor_controller_counter = ui16_TIM2_counter;
throttle_pas_torque_sensor_controller ();
continue;
}
}
I recorded a video showing the LCD5 and look at the oscilloscope that is showing Phase B Current signal and you can clearly see and hear the transition from steps to sinewave, maybe it will help you.
[youtube]EaAqPi7qDiI[/youtube]
The communications controller is not big nor complex:
Code:
void communications_controller (void)
{
static uint8_t tx_buffer[12];
uint8_t ui8_i = 0;
uint8_t ui8_crc = 0;
uint16_t ui16_speed = 6 * ui16_PWM_cycles_counter_total; // * 6 works for my Q85 motor; 16 magnets; Reduction ratio: 12.6
// B0: start package??
tx_buffer [0] = 65;
// B1: battery level: 0: empty box
tx_buffer [1] = 16;
// B2: 24V controller
tx_buffer [2] = 24;
// B3: speed, wheel rotation period, ms; period(ms)=B3*256+B4;
tx_buffer [3] = (ui16_speed >> 8) & 0xff;
tx_buffer [4] = ui16_speed & 0xff;
// B5: error info display
tx_buffer [5] = 0;
// B6: CRC: xor B1,B2,B3,B4,B5,B7,B8,B9,B10,B11
// 0 value so no effect on xor operation for now
tx_buffer [6] = 0;
// B7: moving mode indication, bit
tx_buffer [7] = 2;
// B8: 4x controller current
tx_buffer [8] = (motor_get_current_max () - ADC_MOTOR_CURRENT_MAX_ZERO_VALUE) << 1;
// B9: motor temperature
tx_buffer [9] = 0;
// B10 and B11: 0
tx_buffer [10] = 0;
tx_buffer [11] = 0;
// calculate CRC xor
for (ui8_i = 1; ui8_i <= 11; ui8_i++)
{
ui8_crc ^= tx_buffer[ui8_i];
}
tx_buffer [6] = ui8_crc;
// send the package over UART
for (ui8_i = 0; ui8_i <= 11; ui8_i++)
{
putchar (tx_buffer [ui8_i]);
}
}