Author Topic: PIC PWM slave problem  (Read 774 times)

0 Members and 1 Guest are viewing this topic.

Offline step_s

  • Regular Contributor
  • *
  • Posts: 138
  • Country: dk
PIC PWM slave problem
« on: April 08, 2016, 11:41:08 PM »
Hi there EEVbloggers.
I'm trying to make a synchronous buck-converter, and is controlling it from a PIC16F1574

In order to do this I need to make PWM2 run as a slave to PWM1, to make them match, but I'm having some trouble here.

Code: [Select]
    OSCCON = 0b11110000; //Setup for the internal Oscillator
    TRISA = 0b00011000; //TrisA I/O register
    TRISC = 0b00011000; //TrisC I/O register

    //PWM 1 setup   
    PWM1CLKCON = 0b00000000; //Setting clock
    PWM1PRH = 0b00000000; //Period
    PWM1PRL = 0b01000000;
    PWM1DCH = 0b00000000; //Duty Cycle
    PWM1DCL = 0b00100000;
    PWM1PHH = 0b00000000; //Phase
    PWM1PHL = 0b00000000;
    RA2PPS = 0b00000011; //Set RA2 as output
    PWM1CON = 0b10000000; //Enable PWM1
     //PWM 2 setup
    PWM2CLKCON = 0b00000000; //Setting clock   
    PWM2PRH = 0b00000000; //Period
    PWM2PRL = 0b01000000;
    PWM2DCH = 0b00000000; //Duty Cycle
    PWM2DCL = 0b00100000;
    PWM2PHH = 0b00000000; //Phase
    PWM2PHL = 0b00000000;
    PWM2OFCON = 0b00000000; //Off-set mode
    PWM2CON = 0b10100000; //Enable PWM2

    RC0PPS = 0b00000100; //Set RC0 as output

The PWM2OFCON is here mode 00 = independent, and the two PWMs work, running independently, at the same frequency.
If I then want to make the mode "One-shot slave run mode" then PWM2 has no output. . . It's constantly low.
All the other modes will result in the same problem.

Anyone who know what is going on?
Thanks in advance.

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 1954
  • Country: it
Re: PIC PWM slave problem
« Reply #1 on: April 09, 2016, 06:12:03 PM »
Look at the chip's errata. Not sure if it address your problem but there is an entry named "Continuous Run Slave Offset Mode Anomaly" for the PWM module

Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo