|
|
@ -38,7 +38,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
SPI_HandleTypeDef hspi1;
|
|
|
|
SPI_HandleTypeDef hspi1;
|
|
|
|
|
|
|
|
|
|
|
|
TIM_HandleTypeDef htim1;
|
|
|
|
TIM_HandleTypeDef htim1;
|
|
|
|
TIM_HandleTypeDef htim2;
|
|
|
|
TIM_HandleTypeDef htim2;
|
|
|
|
|
|
|
|
|
|
|
@ -67,7 +66,6 @@ static void MX_SPI1_Init(void);
|
|
|
|
int main(void)
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
// прописать нули в л12 л11
|
|
|
|
|
|
|
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
|
|
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
|
|
|
GPIOA->MODER &= ~(3U << (0 * 2));
|
|
|
|
GPIOA->MODER &= ~(3U << (0 * 2));
|
|
|
|
GPIOA->MODER &= ~(3U << (3 * 2));
|
|
|
|
GPIOA->MODER &= ~(3U << (3 * 2));
|
|
|
@ -87,40 +85,38 @@ int main(void)
|
|
|
|
/* MCU Configuration--------------------------------------------------------*/
|
|
|
|
/* MCU Configuration--------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
|
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
|
|
HAL_Init();
|
|
|
|
HAL_Init();
|
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE BEGIN Init */
|
|
|
|
/* USER CODE BEGIN Init */
|
|
|
|
/* USER CODE END Init */
|
|
|
|
/* USER CODE END Init */
|
|
|
|
|
|
|
|
|
|
|
|
/* Configure the system clock */
|
|
|
|
/* Configure the system clock */
|
|
|
|
SystemClock_Config();
|
|
|
|
SystemClock_Config();
|
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE BEGIN SysInit */
|
|
|
|
/* USER CODE BEGIN SysInit */
|
|
|
|
/* USER CODE END SysInit */
|
|
|
|
/* USER CODE END SysInit */
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize all configured peripherals */
|
|
|
|
/* Initialize all configured peripherals */
|
|
|
|
MX_GPIO_Init();
|
|
|
|
MX_GPIO_Init();
|
|
|
|
MX_TIM2_Init();
|
|
|
|
MX_TIM2_Init();
|
|
|
|
MX_TIM1_Init();
|
|
|
|
MX_TIM1_Init();
|
|
|
|
MX_SPI1_Init();
|
|
|
|
MX_SPI1_Init();
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
uint8_t recData[10] = {0};
|
|
|
|
uint8_t recData[10] = {0};
|
|
|
|
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_SET);
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_SET);
|
|
|
|
//volatile uint32_t start_ticks = DWT->CYCCNT;
|
|
|
|
if (HAL_SPI_Receive(&hspi1, recData, 10, HAL_MAX_DELAY) == HAL_OK) {
|
|
|
|
if (HAL_SPI_Receive(&hspi1, recData, 10, HAL_MAX_DELAY) == HAL_OK) {
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_RESET);
|
|
|
|
//volatile uint32_t end_ticks= DWT->CYCCNT;
|
|
|
|
}
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_RESET);
|
|
|
|
//----------------КАНАЛ 1---------------
|
|
|
|
}
|
|
|
|
FillMode(&modes[0], recData, 0);
|
|
|
|
//----------------КАНАЛ 1---------------
|
|
|
|
//----------------КАНАЛ 2---------------
|
|
|
|
FillMode(&modes[0], recData, 0);
|
|
|
|
FillMode(&modes[1], recData, 5);
|
|
|
|
//----------------КАНАЛ 2---------------
|
|
|
|
|
|
|
|
FillMode(&modes[1], recData, 5);
|
|
|
|
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
|
|
|
|
|
|
/* Infinite loop */
|
|
|
|
/* Infinite loop */
|
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
|
for (int i = 0; i < CHANNELS; i++) {
|
|
|
|
for (int i = 0; i < CHANNELS; i++) {
|
|
|
|
uint8_t T = 1000 / modes[i].f; // период следования импульсов
|
|
|
|
uint8_t T = 1000 / modes[i].f; // период следования импульсов
|
|
|
|
// Считаем, какая частота таймера нужна для получения заданного периода T
|
|
|
|
// Считаем, какая частота таймера нужна для получения заданного периода T
|
|
|
|
uint32_t freq_T_check = (F_CPU * T) / 100;
|
|
|
|
uint32_t freq_T_check = (F_CPU * T) / 100;
|
|
|
@ -136,22 +132,20 @@ int main(void)
|
|
|
|
// Считаем частоту таймера нужна для получения заданного периода T (с новым значением частоты процессора)
|
|
|
|
// Считаем частоту таймера нужна для получения заданного периода T (с новым значением частоты процессора)
|
|
|
|
modes[i].freq_pwm_new = (F_tmp * T) / 1000;
|
|
|
|
modes[i].freq_pwm_new = (F_tmp * T) / 1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
modes[0].pwm_value_res = (modes[0].pwm_value * modes[0].freq_pwm_new) / MAX_PWM_FREQ; // пересчет скважности для 1 канала
|
|
|
|
modes[0].pwm_value_res = (modes[0].pwm_value * modes[0].freq_pwm_new) / MAX_PWM_FREQ; // пересчет скважности для 1 канала
|
|
|
|
modes[1].pwm_value_res = (modes[1].pwm_value * modes[1].freq_pwm_new) / MAX_PWM_FREQ; // пересчет скважности для 2 канала
|
|
|
|
modes[1].pwm_value_res = (modes[1].pwm_value * modes[1].freq_pwm_new) / MAX_PWM_FREQ; // пересчет скважности для 2 канала
|
|
|
|
|
|
|
|
|
|
|
|
HAL_TIM_Base_Start_IT(&htim1);
|
|
|
|
HAL_TIM_Base_Start_IT(&htim1);
|
|
|
|
while (1)
|
|
|
|
while (1) {
|
|
|
|
{
|
|
|
|
/* USER CODE END WHILE */
|
|
|
|
/* USER CODE END WHILE */
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
|
|
|
|
if (channel == 1 && settings_set == 0) {
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
settings_set = 1; // канал 1 настроен
|
|
|
|
if (channel == 1 && settings_set == 0) {
|
|
|
|
} else if (channel == 2 && settings_set == 0) {
|
|
|
|
settings_set = 1; // канал 1 настроен
|
|
|
|
settings_set = 1; // канал 2 настроен
|
|
|
|
} else if (channel == 2 && settings_set == 0) {
|
|
|
|
}
|
|
|
|
settings_set = 1; // канал 2 настроен
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* USER CODE END 3 */
|
|
|
|
/* USER CODE END 3 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|