Getting error in the code

Discussion in 'Programmer's Corner' started by namratha_r, Mar 20, 2015.

  1. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    Code (Text):
    1. void PWM_Set_duty( uint16_t duty_cycle, uint16_t timer_prescalar )
    2. {
    3.      uint16_t reg_value;
    4.      float frequency;
    5.      frequency  = (_XTAL_FREQ/2);
    6.      frequency  = (frequency/timer_prescalar);
    7.      frequency  = (frequency/(PR2+1));             // FREQUENCY OF PWM SIGNAL
    8.  
    9.      frequency  = (frequency*100)/(duty_cycle);
    10.  
    11.      reg_value  = (_XTAL_FREQ)/(uint16_t)(frequency);
    12.      reg_value  = (reg_value/timer_prescalar);
    13.      OC1RS      =  reg_value;
    14.      OC1R       =  OC1RS;  
    15. }
    PWM_Set_Duty.c:13:29: error: expected ')' before 'duty_cycle'
     
  2. MCU88

    Member

    Mar 12, 2015
    360
    35
    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...
     
  3. namratha_r

    Thread Starter New Member

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

    Moderator

    Aug 23, 2012
    4,855
    767
    What't the relationship between (uint16_t) and (frequency) ?
    Are you missing '*' or '/' or ... ?

    reg_value = (_XTAL_FREQ)/(uint16_t)(frequency);
     
  5. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    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 (Text):
    1. reg_value = (_XTAL_FREQ)/(uint16_t)(frequency);
     
  6. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    Code (Text):
    1. 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
     
  7. ScottWang

    Moderator

    Aug 23, 2012
    4,855
    767
    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)
     
  8. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    i solved the problem ... i did not include that prototype function that was the error
     
  9. ScottWang

    Moderator

    Aug 23, 2012
    4,855
    767
    As this?
    void uint16_t PWM_Set_duty( uint16_t duty_cycle, uint16_t timer_prescalar )
     
  10. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    void uint16_t PWM_Set_duty( uint16_t duty_cycle, uint16_t timer_prescalar );
     
Loading...