Skip to content

Bootcamp: Mable Liu#289

Open
mable-liu wants to merge 3 commits intoUWARG:masterfrom
mable-liu:master
Open

Bootcamp: Mable Liu#289
mable-liu wants to merge 3 commits intoUWARG:masterfrom
mable-liu:master

Conversation

@mable-liu
Copy link
Copy Markdown

No description provided.

Comment thread nucleof072rb/Core/Src/main.c Outdated
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
pwmCounts = 100 + ((adcValue * 100) / 1023);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

adcValue is uninitialized here

Comment thread nucleof072rb/Core/Src/main.c Outdated
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
pwmCounts = 100 + ((adcValue * 100) / 1023);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The formula to calculate pwmCounts is also not exactly right. You have the right idea, but your period/prescaler values can be more optimized. You want a higher period and a lower prescaler for a higher resolution signal.

Comment thread nucleof072rb/Core/Src/main.c Outdated
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
pwmCounts = 100 + ((adcValue * 100) / 1023);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, pwmCounts);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This sets the pwm output once. However, if you read a different value from your adc in the while loop, it won't update unless you call this in the while loop.

Comment thread nucleof072rb/Core/Src/main.c Outdated
Comment on lines +108 to +110
txData[0] = 0x01;
txData[1] = 0x80;
txData[2] = 0x00;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor nit- You don't need to call this every time in the while loop

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