pic 18f4620 pwm (enhanced) half bridge mode

Discussion in 'Embedded Systems and Microcontrollers' started by spidermanIIII, Mar 2, 2016.

  1. spidermanIIII

    Thread Starter Member

    Nov 22, 2013
    76
    0
    hi, i want to make pwm and its complementary for half bridge so i choose pic 18f4620 but it give me one pwm but the complementary doesn't appear i read the datasheet he datasheet
    what is the problem please help me
    Code (C):
    1.  
    2. //names
    3.  
    4. //var
    5.  
    6. //modules
    7. void init_(){
    8. trisc.b2=0;
    9. portc.b2=0;
    10.  
    11. trisd=0;
    12. portd=0;
    13.  
    14. CCP1CON=0b10001100;
    15.  
    16.  
    17. TMR2=0;
    18.  
    19. PR2=124;
    20. CCPR1L=20;
    21.  
    22. T2CKPS1_bit=1;
    23. T2CKPS0_bit=0;
    24. TMR2ON_bit=1;
    25. }//init_
    26.  
    27.  
    28. void main() {
    29. //setup
    30. init_();
    31. //loop
    32.  
    33. } //main
    Mod edit: added code tags
     
    Last edited by a moderator: Mar 2, 2016
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,022
    For one thing, you don't have a loop in main. That means that the processor will run init and then be reinitialized by the C runtime when it exits main (it will loop back and run main again and again).
    Try adding while(1); after init_().

    You don't have any useful comments in the code so its hard to know what speed / duty the PWM is supposed to be running at.
     
Loading...