This commit is contained in:
2025-12-18 20:18:07 -06:00
parent 1f6515e609
commit 3c87175342

View File

@@ -47,6 +47,7 @@ TIM_HandleTypeDef htim1;
/* USER CODE BEGIN PV */
uint16_t duty;
int ctr = 7999; // or 65534?
/* USER CODE END PV */
@@ -96,7 +97,7 @@ int main(void)
MX_ADC1_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
//uint16_t val_raw;
uint16_t val_raw;
//float voltage;
HAL_GPIO_WritePin(LED_ERR_GPIO_Port, LED_ERR_Pin, GPIO_PIN_RESET);
@@ -111,19 +112,29 @@ int main(void)
/* USER CODE BEGIN WHILE */
while (1)
{
/*
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 100);
val_raw = HAL_ADC_GetValue(&hadc1);
*/
//duty = (((val_raw/4096)*ctr)/ctr)*100;
duty = 6000;
//duty = (uint16_t)(val_raw/4096);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_4, duty);
HAL_Delay(500);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* This is meant to be run once so it breaks if you put it here. */
//if (HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4) != HAL_OK)
// Error_Handler();
/* TESTS */
/*
// Rising:
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_4, duty);
duty += 100;
@@ -131,6 +142,9 @@ int main(void)
if (duty >= 8000)
duty = 0;
HAL_Delay(10);
*/
/*
// Falling:
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_4, duty);
@@ -139,10 +153,9 @@ int main(void)
if (duty <= 100)
duty = 8000;
*/
/* End Delay, lop this off later */
HAL_Delay(10);
*/
/* END TESTS */
}
/* USER CODE END 3 */
}