Getting error in the code

Thread Starter

namratha_r

Joined Jan 27, 2015
23
Code:
void PWM_Set_duty( uint16_t duty_cycle, uint16_t timer_prescalar )
{
     uint16_t reg_value;
     float frequency;
     frequency  = (_XTAL_FREQ/2);
     frequency  = (frequency/timer_prescalar);
     frequency  = (frequency/(PR2+1));             // FREQUENCY OF PWM SIGNAL

     frequency  = (frequency*100)/(duty_cycle);

     reg_value  = (_XTAL_FREQ)/(uint16_t)(frequency);
     reg_value  = (reg_value/timer_prescalar);
     OC1RS      =  reg_value;
     OC1R       =  OC1RS;   
}
PWM_Set_Duty.c:13:29: error: expected ')' before 'duty_cycle'
 

MCU88

Joined Mar 12, 2015
358
Hello....

An C compiler will produce 1,000 errors from an missing ; or } etc ... So your problem would be anything.

You need to step through the code to debug it...
 

Thread Starter

namratha_r

Joined Jan 27, 2015
23
actually am getting error in this function prototype... and am unable to solve this
Code:
void PWM_Set_duty( uint16_t duty_cycle, uint16_t timer_prescalar )
 

ScottWang

Joined Aug 23, 2012
7,400
What't the relationship between (uint16_t) and (frequency) ?
Are you missing '*' or '/' or ... ?

reg_value = (_XTAL_FREQ)/(uint16_t)(frequency);
 

Thread Starter

namratha_r

Joined Jan 27, 2015
23
first i have initialized frequency as float type . then am doing type casting for frequency by changing into unsigned int and finally loading the value into reg_value
Code:
reg_value = (_XTAL_FREQ)/(uint16_t)(frequency);
 

Thread Starter

namratha_r

Joined Jan 27, 2015
23
Code:
void PWM_Set_duty(int uint16_t duty_cycle, int uint16_t timer_prescalar )
i cant declare this two integer outside the prototype because in the main programming i will be loading some values to this
 

ScottWang

Joined Aug 23, 2012
7,400
void PWM_Set_duty( uint16_t duty_cycle, uint16_t timer_prescalar )

Try to delete two spaces in the brackets.
void PWM_Set_duty(uint16_t duty_cycle, uint16_t timer_prescalar)
 
Top