ADD: ppm input
This commit is contained in:
parent
94907b91cf
commit
a86574bcea
11
Inc/config.h
11
Inc/config.h
|
@ -10,12 +10,15 @@
|
||||||
#define MILLI_PSI (PSI * 1000)
|
#define MILLI_PSI (PSI * 1000)
|
||||||
#define MILLI_V (V * 1000)
|
#define MILLI_V (V * 1000)
|
||||||
|
|
||||||
#define PWM_FREQ 16000 // PWM frequency in Hz
|
#define PWM_FREQ 16000 // PWM frequency in Hz
|
||||||
#define DEAD_TIME 32 // PWM deadtime
|
#define DEAD_TIME 32 // PWM deadtime
|
||||||
|
|
||||||
#define DC_CUR_LIMIT 5 // Motor DC current limit in amps
|
#define DC_CUR_LIMIT 5 // Motor DC current limit in amps
|
||||||
|
|
||||||
#define DEBUG_SERIAL_SERVOTERM
|
#define DEBUG_SERIAL_SERVOTERM
|
||||||
//#define DEBUG_SERIAL_ASCII
|
//#define DEBUG_SERIAL_ASCII
|
||||||
#define DEBUG_BAUD 115200 // UART baud rate
|
#define DEBUG_BAUD 115200 // UART baud rate
|
||||||
//#define DEBUG_I2C_LCD
|
//#define DEBUG_I2C_LCD
|
||||||
|
|
||||||
|
#define CONTROL_PPM // use PPM CONTROL_PPM
|
||||||
|
#define PPM_NUM_CHANNELS 6 // number of PPM channels to receive
|
||||||
|
|
|
@ -117,6 +117,8 @@
|
||||||
#define CHARGER_PIN GPIO_PIN_12
|
#define CHARGER_PIN GPIO_PIN_12
|
||||||
#define CHARGER_PORT GPIOA
|
#define CHARGER_PORT GPIOA
|
||||||
|
|
||||||
|
#define DELAY_TIM_FREQUENCY_US 1000000
|
||||||
|
|
||||||
#define MOTOR_AMP_CONV_DC_AMP 0.02
|
#define MOTOR_AMP_CONV_DC_AMP 0.02
|
||||||
#define ADC_BATTERY_VOLT 0.02647435897435897435897435897436
|
#define ADC_BATTERY_VOLT 0.02647435897435897435897435897436
|
||||||
|
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -35,10 +35,11 @@ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \
|
||||||
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
|
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
|
||||||
Src/system_stm32f1xx.c \
|
Src/system_stm32f1xx.c \
|
||||||
Src/setup.c \
|
Src/setup.c \
|
||||||
Src/stm32f1xx_it.c \
|
Src/control.c \
|
||||||
Src/main.c \
|
Src/main.c \
|
||||||
Src/bldc.c \
|
Src/bldc.c \
|
||||||
Src/comms.c \
|
Src/comms.c \
|
||||||
|
Src/stm32f1xx_it.c \
|
||||||
|
|
||||||
# ASM sources
|
# ASM sources
|
||||||
ASM_SOURCES = \
|
ASM_SOURCES = \
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
|
||||||
|
#include "stm32f1xx_hal.h"
|
||||||
|
#include "defines.h"
|
||||||
|
#include "setup.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
TIM_HandleTypeDef TimHandle;
|
||||||
|
uint16_t ppm_captured_value[PPM_NUM_CHANNELS+1] = {0};
|
||||||
|
uint8_t ppm_count = 0;
|
||||||
|
uint32_t timeout = 0;
|
||||||
|
|
||||||
|
void PPM_ISR_Callback() {
|
||||||
|
// Dummy loop with 16 bit count wrap around
|
||||||
|
uint16_t rc_delay = TIM2->CNT;
|
||||||
|
TIM2->CNT = 0;
|
||||||
|
|
||||||
|
HAL_TIM_Base_Stop(&TimHandle);
|
||||||
|
__HAL_RCC_TIM2_CLK_DISABLE();
|
||||||
|
|
||||||
|
if (rc_delay > 3000) {
|
||||||
|
ppm_count = 0;
|
||||||
|
}
|
||||||
|
else if (ppm_count < PPM_NUM_CHANNELS){
|
||||||
|
timeout = 0;
|
||||||
|
ppm_captured_value[ppm_count] = CLAMP(rc_delay, 1000, 2000) - 1000;
|
||||||
|
ppm_count++;
|
||||||
|
}
|
||||||
|
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||||
|
HAL_TIM_Base_Start(&TimHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PPM_Init() {
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
/*Configure GPIO pin : PA3 */
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||||
|
TimHandle.Instance = TIM2;
|
||||||
|
TimHandle.Init.Period = UINT16_MAX;
|
||||||
|
TimHandle.Init.Prescaler = (SystemCoreClock/DELAY_TIM_FREQUENCY_US)-1;;
|
||||||
|
TimHandle.Init.ClockDivision = 0;
|
||||||
|
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
HAL_TIM_Base_Init(&TimHandle);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
|
||||||
|
}
|
22
Src/main.c
22
Src/main.c
|
@ -30,6 +30,7 @@ extern TIM_HandleTypeDef htim_right;
|
||||||
extern ADC_HandleTypeDef hadc1;
|
extern ADC_HandleTypeDef hadc1;
|
||||||
extern ADC_HandleTypeDef hadc2;
|
extern ADC_HandleTypeDef hadc2;
|
||||||
extern volatile adc_buf_t adc_buffer;
|
extern volatile adc_buf_t adc_buffer;
|
||||||
|
extern volatile uint16_t ppm_captured_value[PPM_NUM_CHANNELS+1];
|
||||||
|
|
||||||
extern volatile int pwml;
|
extern volatile int pwml;
|
||||||
extern volatile int pwmr;
|
extern volatile int pwmr;
|
||||||
|
@ -66,11 +67,18 @@ int main(void) {
|
||||||
MX_ADC2_Init();
|
MX_ADC2_Init();
|
||||||
UART_Init();
|
UART_Init();
|
||||||
|
|
||||||
|
#ifdef CONTROL_PPM
|
||||||
|
PPM_Init();
|
||||||
|
#endif
|
||||||
|
|
||||||
HAL_GPIO_WritePin(OFF_PORT, OFF_PIN, 1);
|
HAL_GPIO_WritePin(OFF_PORT, OFF_PIN, 1);
|
||||||
|
|
||||||
HAL_ADC_Start(&hadc1);
|
HAL_ADC_Start(&hadc1);
|
||||||
HAL_ADC_Start(&hadc2);
|
HAL_ADC_Start(&hadc2);
|
||||||
|
|
||||||
|
int lastSpeedL = 0, lastSpeedR = 0;
|
||||||
|
int speedL = 0, speedR = 0;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
HAL_Delay(0);
|
HAL_Delay(0);
|
||||||
// int milli_cur = 3000;
|
// int milli_cur = 3000;
|
||||||
|
@ -83,8 +91,18 @@ int main(void) {
|
||||||
// milli_vel_error_sum = CLAMP(milli_vel_error_sum, -200000, 200000);
|
// milli_vel_error_sum = CLAMP(milli_vel_error_sum, -200000, 200000);
|
||||||
// pwm = CLAMP(milli_vel_cmd / 5 + milli_vel_error_sum / 200, -500, 500);
|
// pwm = CLAMP(milli_vel_cmd / 5 + milli_vel_error_sum / 200, -500, 500);
|
||||||
// cmdl = 70;
|
// cmdl = 70;
|
||||||
pwml = 150;
|
|
||||||
pwmr = 150;
|
#ifdef CONTROL_PPM
|
||||||
|
speedR = -(CLAMP((((ppm_captured_value[1]-500)-(ppm_captured_value[0]-500)/2.0)*(ppm_captured_value[2]/500.0)), -800, 800));
|
||||||
|
speedL = -(CLAMP((((ppm_captured_value[1]-500)+(ppm_captured_value[0]-500)/2.0)*(ppm_captured_value[2]/500.0)), -800, 800));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ((speedL < lastSpeedL + 50 && speedL > lastSpeedL - 50) && (speedR < lastSpeedR + 50 && speedR > lastSpeedR - 50)) {
|
||||||
|
pwmr = speedR;
|
||||||
|
pwml = speedL;
|
||||||
|
}
|
||||||
|
lastSpeedL = speedL;
|
||||||
|
lastSpeedR = speedR;
|
||||||
|
|
||||||
// if(vel > milli_vel_cmd){
|
// if(vel > milli_vel_cmd){
|
||||||
// HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1);
|
// HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1);
|
||||||
|
|
|
@ -164,6 +164,13 @@ void SysTick_Handler(void) {
|
||||||
/* USER CODE END SysTick_IRQn 1 */
|
/* USER CODE END SysTick_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void EXTI3_IRQHandler(void)
|
||||||
|
{
|
||||||
|
PPM_ISR_Callback();
|
||||||
|
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_3);
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* STM32F1xx Peripheral Interrupt Handlers */
|
/* STM32F1xx Peripheral Interrupt Handlers */
|
||||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||||
|
|
1319
build/hover.hex
1319
build/hover.hex
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue