Mohamed Ibrahim Bootcamp: Complete EFS bootcamp motor tester#295
Open
MIbrahim-7 wants to merge 2 commits into
Open
Mohamed Ibrahim Bootcamp: Complete EFS bootcamp motor tester#295MIbrahim-7 wants to merge 2 commits into
MIbrahim-7 wants to merge 2 commits into
Conversation
MIbrahim-7
commented
May 13, 2026
- Configured SPI1 for communication with the external ADC
- Configured TIM1 Channel1 for PWM output
- Added ADC read logic using SPI
- Mapped 10-bit ADC values to a 1000-2000 PWM range
- Updated PWM output continuously in the main loop
| uint8_t rxData[2] = {0x00, 0x00}; | ||
|
|
||
| HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET); | ||
| HAL_SPI_TransmitReceive(&hspi1, txData, rxData, 2, HAL_MAX_DELAY); |
| HAL_SPI_TransmitReceive(&hspi1, txData, rxData, 2, HAL_MAX_DELAY); | ||
| HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); | ||
|
|
||
| uint16_t adcValue = ((rxData[0] << 8) | rxData[1]) & 0x03FF; |
There was a problem hiding this comment.
will need to change this to get a 10-bit result
|
|
||
| uint16_t adcToPwm(uint16_t adcValue) | ||
| { | ||
| return 1000 + ((adcValue * 1000) / 1023); |
There was a problem hiding this comment.
you are trying to maximize your period try using the equations to get a min and max instead of 1000
|
|
||
| /* USER CODE END TIM1_Init 1 */ | ||
| htim1.Instance = TIM1; | ||
| htim1.Init.Prescaler = 47; |
There was a problem hiding this comment.
Although this prescaler value is right you want to try and lower this as much as you to maximize your counter period
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.