PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891

    Default PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC

    Hi there,

    I'm finishing my cooking-timer project and first time tried the PWM (ECCP) half-bridge functionality (when pin P1A is HIGH, P1B is LOW, next cycle inverts and so forth) on my PIC 16f690.

    The piezo-sounder I have works best (= is the loudest) @ 4kHz.

    The idea (not new at all) is to augment my piezo-sounder's loudness by inverting its power polarity @ 4kHz (kind of 10V peak-to-peak). As a matter of fact, it works very well

    Since my piezo-sounder draws not more than 1,5mA, I have connected it directly to the respective PIC's pins P1A & P1B.

    Is this way of doing okay or am I going to have a surprise in a certain period of time?
    Roger

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC

    Hello Roger,

    I have done this many times ( because it works very well on getting a higher sound with 2 pins inverted ) and never had any problems.
    The only difference is that I use a small resistor ( 100 ohms ) between the pin and the piezo ( one for each pin ).
    The frequency depends on the piezo so it's best to test to see which is the optimal frequency ( as you did ).

    Regards
    Rui

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Re: PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC

    Quote Originally Posted by flotulopex View Post
    augment ... piezo-sounder's loudness by inverting its power polarity @ 4kHz (kind of 10V peak-to-peak).
    Please, can you post the code for this particular thing ? Thanks !

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC

    That's the code, well... it's just THE part of the cooking-timer code to make that "half-bridge" PWM work:
    Code:
    '-------------------------------------------------------------------------------
    ' PIC 16F690 Fuses (MPASM)
    @ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_HS_OSC &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
    
    '-------------------------------------------------------------------------------
    ' Registers   76543210
    OPTION_REG = %10000110 ' Pull-Ups OFF, Prescaler TMR0 1:128
    ANSEL      = %00000000 ' Select analog inputs Channels 0 to 7
    ANSELH     = %00000001 ' Select analog inputs Channels 8 to 11
    WPUA       = %00000000 ' Select weak pull-ups
    WPUB       = %00000000 ' Select weak pull-ups
    ADCON0     = %10000000 ' AD Module
    ADCON1     = %00000000 ' AD control register
    CM1CON0    = %00000000 ' Comparator1 Module
    CM2CON0    = %00000000 ' Comparator2 Module
    INTCON     = %10100000 ' INTerrupts CONtrol; GIE=1, T0IE=1
    TRISA      = %00000000 ' Select Input/Output (0 to 5)
    PORTA      = %00000000 ' Set High/Low (0 to 5)
    TRISB      = %00110000 ' Select Input/Output (4 to 7)
    PORTB      = %00000000 ' Set High/Low (4 to 7)
    TRISC      = %01000000 ' Select Input/Output (0 to 7)
    PORTC      = %00000000 ' Set High/Low (0 to 7)
    
    ' HPWM registers
    T2CON      = %00000101 ' Timer2 = ON (bit2), prescaler (bits1:0) 00=1, 01=4, 1x=16
    CCP1CON    = %10001100 ' Select PWM Mode (%00001100 = PWM module ON)
    CCPR1L     = 62        ' Dutycycle set to 50% (= percentage of PR2)
    PR2        = 124       ' Freq 4kHz
    Roger

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC

    Just as a precaution I would recommend to have the outputs at the same logic level when you do not want the sounder work. Thats because piezo do not like DC voltage.

    Ioannis

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    574


    Did you find this post helpful? Yes | No

    Default Re: PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC

    Thanks Mr.Flotulopex and Mr.Ioannis !
    It's verry usefull.

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC

    ...I would recommend to have the outputs at the same logic level...
    When the souder is not used, I set CCP1CON register to 0.

    Is this okay?
    Roger

  8. #8
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC

    ....hum, sorry for my silly question

    Just measured the ports and they need to be reset.

    Thanks for noticing Ioannis
    Last edited by flotulopex; - 9th October 2015 at 07:17.
    Roger

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: PWM (ECCP) - piezo-sounder directly connected to half-bridge on PIC

    As you observed Roger, you must be in luck to have both ports at the same level. They will be in a random state.

    Ioannis

Similar Threads

  1. Replies: 4
    Last Post: - 7th June 2011, 06:02
  2. PWM with PIC16F88 controlling h-bridge
    By deimantas in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 20th May 2010, 23:03
  3. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 23:18
  4. 18F4620 HPWM Half Bridge Mod problem
    By showtime in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd November 2007, 13:55
  5. Using HPWM in half bridge mode on 16f690
    By Chris Barron in forum mel PIC BASIC
    Replies: 0
    Last Post: - 29th December 2006, 12:18

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts