From 0728904359dc77ee5cd2d9bd37b5c5a65e54b3a4 Mon Sep 17 00:00:00 2001 From: Rene Hopf Date: Mon, 5 Dec 2016 17:04:48 +0100 Subject: [PATCH] comments, cleanup --- shared/defines.h | 1 + src/comps/enc_cmd.comp | 57 ------------------------------------------ src/link.c | 1 + src/main.c | 2 +- stm32f103/src/main.c | 8 +++--- 5 files changed, 7 insertions(+), 62 deletions(-) diff --git a/shared/defines.h b/shared/defines.h index 515a35fd..80202d30 100644 --- a/shared/defines.h +++ b/shared/defines.h @@ -48,6 +48,7 @@ extern "C" { #define STRINGIFY(x) STRINGIFY_(x) //TODO: change type to typeof() +//TODO: change __old_val__ to something more useful #define RISING_EDGE(sig)\ ({static float __old_val__ = 0.0; uint8_t ret = (sig) > __old_val__; __old_val__ = (sig); ret;}) diff --git a/src/comps/enc_cmd.comp b/src/comps/enc_cmd.comp index 4377bca6..8c0d9dab 100644 --- a/src/comps/enc_cmd.comp +++ b/src/comps/enc_cmd.comp @@ -92,60 +92,3 @@ RT( ); ENDCOMP; - -//http://stackoverflow.com/questions/32947972/stm32-how-to-make-pulse-count-up-down-with-timer -// #include "mbed.h" -// #include "stm32f4xx.h" -// #include "stm32f4xx_hal_tim_ex.h" -// -// TIM_HandleTypeDef timer; -// TIM_Encoder_InitTypeDef encoder; -// -// //direction to PA_9 -- step to PA_8 -// -// int main(){ -// GPIO_InitTypeDef GPIO_InitStruct; -// __TIM1_CLK_ENABLE(); -// __GPIOA_CLK_ENABLE(); -// GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9; -// GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; -// GPIO_InitStruct.Pull = GPIO_PULLDOWN; -// GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; -// GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; -// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); -// -// timer.Instance = TIM1; -// timer.Init.Period = 0xffff; -// timer.Init.Prescaler = 1; -// timer.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; -// timer.Init.CounterMode = TIM_COUNTERMODE_UP; -// -// -// encoder.EncoderMode = TIM_ENCODERMODE_TI1; -// encoder.IC1Filter = 0x0f; -// encoder.IC1Polarity = TIM_INPUTCHANNELPOLARITY_RISING; //step signal -// encoder.IC1Prescaler = TIM_ICPSC_DIV1; -// encoder.IC1Selection = TIM_ICSELECTION_DIRECTTI; -// -// encoder.IC2Filter = 0x0f; -// encoder.IC2Polarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE; //check direction -// encoder.IC2Prescaler = TIM_ICPSC_DIV1; -// encoder.IC2Selection = TIM_ICSELECTION_INDIRECTTI; -// -// HAL_TIM_Encoder_Init(&timer, &encoder); -// HAL_TIM_Encoder_Start(&timer,TIM_CHANNEL_1); -// -// -// TIM1->EGR = 1; // Generate an update event -// TIM1->CR1 = 1; // Enable the counter -// -// -// while (1) { -// int16_t count1; -// count1=TIM1->CNT; -// -// printf("%d\r\n", count1); -// wait(1.0); -// -// }; -// } diff --git a/src/link.c b/src/link.c index dcc851aa..69bb4959 100644 --- a/src/link.c +++ b/src/link.c @@ -153,6 +153,7 @@ void link_pid(){ hal_link_pins("fault0.brake", "io0.brake"); hal_link_pins("fault0.hv_fan", "io0.fan"); + //TODO: merge enable_out and enable_pid hal_link_pins("fault0.enable_out", "hv0.enable"); hal_link_pins("fault0.enable_pid", "pid0.enable"); diff --git a/src/main.c b/src/main.c index d643d7dd..48963828 100644 --- a/src/main.c +++ b/src/main.c @@ -313,7 +313,7 @@ int main(void) frt_period_time_hal_pin = hal_map_pin("net0.frt_period"); link_pid(); - hal_comp_init(); + hal_comp_init();//call init function of all comps if(hal.pin_errors + hal.comp_errors == 0){ hal_start(); diff --git a/stm32f103/src/main.c b/stm32f103/src/main.c index ae6dfccf..246efe04 100644 --- a/stm32f103/src/main.c +++ b/stm32f103/src/main.c @@ -20,7 +20,7 @@ #define ACS_DOWN 3000.0 #define ACS_OFFSET 2.5 -#define AMP(a) ((a * AREF / ARES * (ACS_DOWN + ACS_UP) / ACS_DOWN - ACS_OFFSET) / ACS_VPA) +#define AMP(a) (((a) * AREF / ARES * (ACS_DOWN + ACS_UP) / ACS_DOWN - ACS_OFFSET) / ACS_VPA) #else //iramx v3.1-v3.3 hardware #define RCUR 0.0181//shunt @@ -34,12 +34,12 @@ #define PWM_V TIM1->CCR2 #define PWM_W TIM1->CCR3 -#define AMP(a) ((a * AREF / ARES - AREF / (R10 + R11) * R11) / (RCUR * R10) * (R10 + R11)) -#define TEMP(a) (log10f(a * AREF / ARES * TPULLUP / (AREF - a * AREF / ARES)) * (-53) + 290) +#define AMP(a) (((a) * AREF / ARES - AREF / (R10 + R11) * R11) / (RCUR * R10) * (R10 + R11)) +#define TEMP(a) (log10f((a) * AREF / ARES * TPULLUP / (AREF - a * AREF / ARES)) * (-53) + 290) #endif -#define VOLT(a) (a / ARES * AREF / VDIVDOWN * (VDIVUP + VDIVDOWN)) +#define VOLT(a) ((a) / ARES * AREF / VDIVDOWN * (VDIVUP + VDIVDOWN)) volatile uint16_t ADCConvertedValue[100];//DMA buffer for ADC volatile uint8_t rxbuf[50];//DMA buffer for UART RX