cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in duty cycle

deepak
Associate II
Posted on July 11, 2014 at 16:14

Dear sir,

i have following conditions.

the problem is that, my actual value & compiler value are not matching.

in debug options.

1) i am getting duty cycle on o.scope less than 2% the actual calculations.

look forward to hearing you soon.

{

Duty_cycle_buck=90-(80*Buck_Ref_mv/3000);

 TIM_OCInitStructure.TIM_Pulse = (uint16_t) (((uint32_t) Duty_cycle_buck*(TimerPeriod - 1)) / 100);// duty cycle formula

TIM_OC1Init(TIM1, &TIM_OCInitStructure);//OC1 selects PA8

}

4 REPLIES 4
Posted on July 11, 2014 at 16:30

i have following conditions. the problem is that, my actual value & compiler value are not matching.

Yet you totally fail to convey enough detail that would let anyone do analysis!

Here's a thought, specify what the Period value is for the timer, and what the Pulse value is. Understanding that Period is programmed with N-1 and Pulse with (Percent * N) / 100, and you must do the computation with enough bits of precision so as not to get invalid answers.

What are the types, range and values of the other variables. 80 * 3000 won't fit in 16-bit

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
deepak
Associate II
Posted on July 12, 2014 at 09:00

Thanks Mr Clive,

My calculation is not a ''80*3000'' its a 80/3000.

as per formula,

duty cycle=90-((80*buck_ref)/3000)

& buck ref is calculating from adc.

here if external buck ref=1volts then in calculation buck_ref will be 1000 (mv).

As i am looking for the duty cycle lesser than 90% & it should be variable from 10% to 90%.

Kindly take review on timer code.

TIM3->PSC = 23999;      // Set prescaler to 24 000 (PSC + 1)

TIM3->ARR = 500;       // Auto reload value 1000 (FOR 1 SECOND DELAY)

TIM3->DIER = TIM_DIER_UIE; // Enable update interrupt (timer level)

TIM3->CR1 = TIM_CR1_CEN;// Enable timer

NVIC_EnableIRQ(TIM3_IRQn); // Enable interrupt from TIM3 (NVIC level)

is any info are you looking for.

my email id is deepak.chikane@gmail.com

Look forward to hearing you soon.

Posted on July 12, 2014 at 13:26

My calculation is not a ''80*3000'' its a 80/3000.

Yes, I know, and the reason I reversed the math is because there was no indication of range provided, so I picked a number I felt was reasonable. 80000 also doesn't fit either.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 12, 2014 at 13:36

Try

duty cycle=90-((8*buck_ref)/300)

Which would work for 0-8191mV, compared to the prior version of 0-819.1mV if the math is done with 16-bit variables.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..