not sure why im so bad at math
This commit is contained in:
@@ -36,9 +36,14 @@ extern "C" {
|
|||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN PD */
|
/* USER CODE BEGIN PD */
|
||||||
#define Print2UART1 int __io_putchar(int data) // prints to serial monitor
|
#define Print2UART1 int __io_putchar(int data) // prints to serial monitor
|
||||||
//float duty = 58.52 // (((2396*4096)*65534)/65534)*100
|
|
||||||
//int duty = 59;
|
int duty;
|
||||||
float duty = 58.52;
|
/*
|
||||||
|
* We are going to set this value repeatedly as such:
|
||||||
|
* CCR
|
||||||
|
* DC(%) = ----------- * 100
|
||||||
|
* ARR + 1
|
||||||
|
*/
|
||||||
|
|
||||||
/* USER CODE END PD */
|
/* USER CODE END PD */
|
||||||
|
|
||||||
@@ -121,20 +126,19 @@ main(void)
|
|||||||
HAL_ADC_PollForConversion(&hadc1, 100); //poll ADC1 periph, timeout 100ms
|
HAL_ADC_PollForConversion(&hadc1, 100); //poll ADC1 periph, timeout 100ms
|
||||||
|
|
||||||
rawValue = HAL_ADC_GetValue(&hadc1);
|
rawValue = HAL_ADC_GetValue(&hadc1);
|
||||||
|
printf("The value is %hu volts.\r\n", rawValue);
|
||||||
|
|
||||||
HAL_Delay(500);
|
HAL_Delay(500);
|
||||||
|
|
||||||
//volts = rawValue; // TODO change this to an actual conversion
|
volts = ((float)rawValue / 4096) * 3; // convert to voltage from 0 to 3.0
|
||||||
volts = (float)rawValue / duty;
|
|
||||||
|
|
||||||
//printf("The value is %hu volts.\r\n", volts);
|
|
||||||
printf("The value is %f volts.\r\n", volts);
|
printf("The value is %f volts.\r\n", volts);
|
||||||
|
|
||||||
HAL_Delay(500);
|
HAL_Delay(500);
|
||||||
|
|
||||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty); // TODO dude what is going on
|
duty = ((float)rawValue / 4096) * 65534;
|
||||||
// rawValue/4096*65545
|
|
||||||
// i think it works now?
|
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty);
|
||||||
|
|
||||||
HAL_Delay(100);
|
HAL_Delay(100);
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user