cancel
Showing results for 
Search instead for 
Did you mean: 

Changing Brightness

Priyank
Associate III

Hi I am having some trouble adjusting the brightness for the STM32F7.

I used this in main.c, and externed it 

I tried using this in model.cpp and in main.c, neither seems to adjust the brightness of the display.

 

void setDutyCycle(float duty_cycle) {
  if (duty_cycle > 100) duty_cycle = 100;
  if (duty_cycle < 0  ) duty_cycle = 0;

  float pw_resolution = (((float)99 + 1.0f) / 100.0f);

  uint16_t pw_desired = pw_resolution * duty_cycle;
  __HAL_TIM_SET_COMPARE( &htim2, TIM_CHANNEL_3, pw_desired );
}

 


Code formatting applied - please see How to insert source code for future reference

 

2 REPLIES 2

Attach a scope, check the output.

Drive the TIM2->CCR3 manually, confirm it does what you expect.

Confirm you're writing in the values you think you are.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Peter BENSCH
ST Employee

@Priyank Your problem starts with the fact that you absolutely want to pass the duty cycle as a float. Wouldn't it be easier to treat it as a percentage and e.g. uint8_t?

But even if you use float, you must also use everything that has to do with it as float. For example, you query:

if(duty_cycle > 100)...

which should be expressed as:

if(duty_cycle > 100.0)...

Anyway, the best thing would also be to work with direct register programming first, as @Tesla DeLorean has recommended.

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.