Skip to content

Mohamed Ibrahim Bootcamp: Complete EFS bootcamp motor tester#295

Open
MIbrahim-7 wants to merge 2 commits into
UWARG:masterfrom
MIbrahim-7:master
Open

Mohamed Ibrahim Bootcamp: Complete EFS bootcamp motor tester#295
MIbrahim-7 wants to merge 2 commits into
UWARG:masterfrom
MIbrahim-7:master

Conversation

@MIbrahim-7
Copy link
Copy Markdown

  • 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

Comment thread nucleof072rb/Core/Src/main.c Outdated
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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ADC chip requires 3 bytes

Comment thread nucleof072rb/Core/Src/main.c Outdated
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need to change this to get a 10-bit result

Comment thread nucleof072rb/Core/Src/main.c Outdated

uint16_t adcToPwm(uint16_t adcValue)
{
return 1000 + ((adcValue * 1000) / 1023);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this prescaler value is right you want to try and lower this as much as you to maximize your counter period

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants