diff --git a/Core/Src/main.cpp b/Core/Src/main.cpp index 352ae31..296939b 100644 --- a/Core/Src/main.cpp +++ b/Core/Src/main.cpp @@ -36,9 +36,14 @@ extern "C" { /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ #define Print2UART1 int __io_putchar(int data) // prints to serial monitor -//float duty = 58.52 // (((2396*4096)*65534)/65534)*100 -//int duty = 59; -float duty = 58.52; + +int duty; +/* + * We are going to set this value repeatedly as such: + * CCR + * DC(%) = ----------- * 100 + * ARR + 1 + */ /* USER CODE END PD */ @@ -121,20 +126,19 @@ main(void) HAL_ADC_PollForConversion(&hadc1, 100); //poll ADC1 periph, timeout 100ms rawValue = HAL_ADC_GetValue(&hadc1); + printf("The value is %hu volts.\r\n", rawValue); HAL_Delay(500); - //volts = rawValue; // TODO change this to an actual conversion - volts = (float)rawValue / duty; - - //printf("The value is %hu volts.\r\n", volts); + volts = ((float)rawValue / 4096) * 3; // convert to voltage from 0 to 3.0 printf("The value is %f volts.\r\n", volts); HAL_Delay(500); - __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty); // TODO dude what is going on - // rawValue/4096*65545 - // i think it works now? + duty = ((float)rawValue / 4096) * 65534; + + __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty); + HAL_Delay(100); /* USER CODE END WHILE */