cancel
Showing results for 
Search instead for 
Did you mean: 

unable to get the output from the code:

Murali3252
Associate

Hi Community.

I am Running a code which takes two adc values to generate duty  and one timer for PWM generation.

 

Elaborately i am running an MPPT code by taking voltage and current from PV panel which is read by PA0 and PA1 of STM32F446re micro controller in DMA mode which the output will be duty from the MPPT code.

Now i just want to generate PWM from correspond duty which is from MPPT code. i have taken Timer 1 CH1 for this to get the PWM. is this correct way to generate pwm from duty.if not please suggest me how to generate pwm from duty with the help of timer?

is my approach is correct .i have given my code here below.

please let me know if there are any changes is required

 

CODE is attached in the pdf document.

1 REPLY 1
Sarra.S
ST Employee

Hello @Murali3252

It's a bit tricky to read 28 pages of code in Microsoft Word, alternatively, you might want to attach your zipped project or a link to a GitHub repo.

Apart from that, the duty cycle for the PWM is typically a value between 0 and ARR, not a floating point percentage, so you need to convert the floating duty calculated by the MPPT algorithm into a compare value that the timer can use.

So instead of : 

void vary_pwm_duty()
{
    TIM1->CCR1 = duty; // Set PWM duty cycle
}

and the duty is a floating number between 0.0 and 1.0, you need to cast it to an (uint32_t) which is the type of data expected by the timer's CCR register. 

Also, I can't find where you are starting the PWM output? 

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.