-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bootcamp: Ameen #135
base: master
Are you sure you want to change the base?
Bootcamp: Ameen #135
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Work! I left some comments here. Please ask any question if the feedback / the BootCamp is confusing to you.
/* USER CODE BEGIN WHILE */ | ||
while (1) | ||
{ | ||
/* USER CODE END WHILE */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to pull down the Chip Select line before calling the SPI function.
rx_buffer_split[0] = rx_buffer_split[0] & 0b00000011; //isolating B9 and B8 | ||
uint16_t rx_buffer = (rx_buffer_split[0] << 8) + rx_buffer_split[1]; | ||
if(rx_buffer > 65535 || rx_buffer < 0) continue; | ||
HAL_TIM_PWM_ConfigChannel(&htim1, rx_buffer, TIM_CHANNEL_1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this function is the correct function to manipulate the PWM duty cycle here. You are also missing a piece of math to convert the ADC data to PWM timer counts.
ADC generates a number that vary from 0 to (2^10-1) since the resolution of this ADC is 10 bits.
Your PWM timer has 65535 counts in one period. When 5% of 65535 is on high level, 95% of counts on low level, you have a 5% duty cycle and that maps to 0 from the ADC data.
If the PWM has a 10% duty cycle, meaning 10% of 65535 counts on high, 90% on low. That maps to the max number from ADC.
Your math is supposed to handle this mapping from ADC value to PWM counts, and find the correct HAL function to change the Timer from high to low.
Changes made:
-configured pinout diagram to generate code