Using PWM output as I/O

Discussion in 'Embedded Systems and Microcontrollers' started by johndeaton, Oct 15, 2016.

  1. johndeaton

    Thread Starter Member

    Sep 23, 2015
    48
    3
    Hi All,

    I have an application where I want a pwm output at times and a constant on signal some times. I'm using a Microchip PIC16F1508. Is there a way to do this without reinitializing the port and pin every time?

    Thanks
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,173
    1,797
    You need to read the datasheet very carefully to see if you can set the PWM duty cycle to 0% and 100%. If you can do that then you can have the pin output a constant value.
     
    Last edited: Oct 15, 2016
    MMcLaren likes this.
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,348
    1,029
    Probably. As PB indicated according to Equation 23-2:
    That implies that if DCH/L == 0, the pulse width is 0 so the pin level should be constant low.

    You'll get a constant high if you set the pulse width > the period as noted later in the section:
    That said, I would prefer to do things explicitly i.e. turn the PWM off for a steady pin level then back on AND re-initialized for PWM. That way you avoid worrying about left over time in the PWM registers before the pin changes etc. But it should more or less work as you described. Give it a try and let us know.

    Good luck.
     
    Papabravo likes this.
  4. NorthGuy

    Active Member

    Jun 28, 2014
    605
    121
    Simply set the PWMxOE bit to 1 if you want the pin to be controlled by the PWM module or to 0 if you want the pin to be controlled by LAT.
     
  5. hasanz89

    New Member

    Jul 10, 2014
    5
    0
    This is the schematic ac-dc adapter on my thread about zener diode as a shunt regulator I found the zener diode is impractically in this circuit .Instead it used 1N4148 semiconductor diode
     
Loading...