mirror of https://github.com/rusefi/bldc.git
Some longboard updates and a timer struct write move
This commit is contained in:
parent
cd52f94184
commit
a0024affd4
|
@ -50,6 +50,7 @@ static volatile systime_t last_uart_update_time;
|
|||
|
||||
// Private functions
|
||||
static void set_output(float output);
|
||||
static uint16_t middle_of_3(uint16_t a, uint16_t b, uint16_t c);
|
||||
|
||||
/*
|
||||
* This callback is invoked when a transmission buffer has been completely
|
||||
|
@ -82,7 +83,15 @@ static void rxerr(UARTDriver *uartp, uartflags_t e) {
|
|||
static void rxchar(UARTDriver *uartp, uint16_t c) {
|
||||
(void)uartp;
|
||||
|
||||
out_received = ((float)c / 128) - 1.0;
|
||||
static uint16_t c1 = 128;
|
||||
static uint16_t c2 = 128;
|
||||
|
||||
uint16_t med = middle_of_3(c, c1, c2);
|
||||
|
||||
c2 = c1;
|
||||
c1 = c;
|
||||
|
||||
out_received = ((float)med / 128) - 1.0;
|
||||
last_uart_update_time = chTimeNow();
|
||||
}
|
||||
|
||||
|
@ -183,4 +192,17 @@ static void set_output(float output) {
|
|||
}
|
||||
}
|
||||
|
||||
static uint16_t middle_of_3(uint16_t a, uint16_t b, uint16_t c) {
|
||||
uint16_t middle;
|
||||
|
||||
if ((a <= b) && (a <= c)) {
|
||||
middle = (b <= c) ? b : c;
|
||||
} else if ((b <= a) && (b <= c)) {
|
||||
middle = (a <= c) ? a : c;
|
||||
} else {
|
||||
middle = (a <= b) ? a : b;
|
||||
}
|
||||
return middle;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
2
comm.c
2
comm.c
|
@ -245,8 +245,6 @@ void comm_printf(char* format, ...) {
|
|||
if(len>0) {
|
||||
packet_send_packet((unsigned char*)print_buffer, (len<254)? len+1: 255, 0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void comm_send_samples(uint8_t *data, int len) {
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
*/
|
||||
#define MCPWM_CURRENT_MAX 35.0 // Current limit in Amperes (Upper)
|
||||
#define MCPWM_CURRENT_MIN -30.0 // Current limit in Amperes (Lower)
|
||||
#define MCPWM_MAX_ABS_CURRENT 100.0 // The maximum absolute current above which a fault is generated
|
||||
#define MCPWM_MAX_ABS_CURRENT 80.0 // The maximum absolute current above which a fault is generated
|
||||
#define MCPWM_SLOW_ABS_OVERCURRENT 1 // Use the filtered (and hence slower) current for the overcurrent fault detection
|
||||
#define MCPWM_IN_CURRENT_MAX 25.0 // Input current limit in Amperes (Upper)
|
||||
#define MCPWM_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower)
|
||||
#define MCPWM_RPM_MAX 50000.0 // The motor speed limit (Upper)
|
||||
|
|
4
mcpwm.c
4
mcpwm.c
|
@ -1939,10 +1939,10 @@ static void commutate(void) {
|
|||
}
|
||||
|
||||
static void set_next_timer_settings(mc_timer_struct *settings) {
|
||||
memcpy((void*)&timer_struct, settings, sizeof(mc_timer_struct));
|
||||
|
||||
chSysLock();
|
||||
|
||||
memcpy((void*)&timer_struct, settings, sizeof(mc_timer_struct));
|
||||
|
||||
volatile uint32_t cnt = TIM1->CNT;
|
||||
volatile uint32_t top = TIM1->ARR;
|
||||
|
||||
|
|
Loading…
Reference in New Issue