• AVR Freaks

PWM anomaly

Author
upand_at_them
Super Member
  • Total Posts : 681
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: offline
2020/09/20 13:55:12 (permalink)
0

PWM anomaly

I have two pushbuttons (on RA2 and RA3), a buzzer (on RC3/CCP2), and a small OLED display (hardware I2C on RC0/SCL and RC1/SDA) connected to a PIC16F1825.  I also have Timer1 configured with a watch crystal for RTC.
 
I'm showing a weird problem with the PWM (using Timer2) for the buzzer (technically a magnetic transducer, not piezo).  On a button press, I turn the buzzer on for a short time to generate a beep.  And then turn it off.  After three presses of either button, the PWM ends up idling in the HIGH state.  It will still "beep", but it says ON after the beep.  This causes an annoying hiss in the buzzer, and can't be good for it.  PWM is configured for active HIGH, which return to LOW at the end of the period.  I don't have any code that checks for "3".  In fact, I'm sounding the buzzer only by turning on and off Timer2.  Also, if I remove all of the display code (which is also on PORTC) the problem disappears.  Just removing the writes to the display doesn't fix it I have to also remove the display initialization as well.
 
Is this some conflicting interaction between the MSSP and PWM?  Why doesn't the PWM output return to LOW?  And why only after the display has been initialized?
 
Is this caused by my method of controlling the PWM by switching Timer2 off?  If so, what is the proper method of enabling and disabling PWM?
 
Sorry, no code...I'd have to work on reducing it to the minimum to cause the problem.
post edited by upand_at_them - 2020/09/20 14:29:11
#1

2 Replies Related Threads

    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 12017
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PWM anomaly 2020/09/20 14:41:47 (permalink)
    +2 (2)
    Is there something in the data sheet that would make you believe that the PWM would somehow "know" its timer had been turned off?  And even if it did, how could it continue operating to finish the current cycle?
     
    Set the duty cycle to 0 to stop the PWM.
    #2
    upand_at_them
    Super Member
    • Total Posts : 681
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: offline
    Re: PWM anomaly 2020/09/20 14:56:54 (permalink)
    +1 (1)
    Indeed!  Thank you.  It works.
    #3
    Jump to:
    © 2020 APG vNext Commercial Version 4.5