Menu

PWM Rat Botherer

2015-11-24
2015-11-24
  • Charles R. Veres

    This program is based on EvanV's blinky for 16F628A. (Thank You) I am posting it as an example of how to use hardware PWM to generate ultrasonic square waves.

    '''PWM Rat Botherer based on EvanV LED Blinker
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''This program emits square waves on pin 9.

    '''
    '''@author EvanV plus works of others including Chip V.
    '''@licence GPL
    '''@version 1.0a
    '''@date 31.01.2015
    '''**************

    ; ----- Configuration
    #chip 16F628A, 4
    #config LVP = Off

    ' #include
    ' no solution specifc includes, default includes are always included ; no solution specifc includes, default includes are always included

    ; ----- Define Hardware settings
    ' this is required to tell the microprocessor the port is an output
    ' (PORTB.3 = Pin 9 on PIC16f628A)
    Dir PORTB.3 Out

    ; ----- Variables
    ' none specified in the example. All byte variables are defined upon use.

    ; ----- Main body of program commences here.

    Start:
    HPWM 1,22,128 'PWM to output 1 at 22 KHz, 50% duty cycle
    wait 1 second
    PWMOff
    wait 1 second

    HPWM 1,23,128 '23 KHz
    wait 1 second
    PWMOff
    wait 1 second
    
    HPWM 1,24,128 '24 KHz
    wait 1 second
    PWMOff
    wait 1 second
    
    HPWM 1,25,128 '25 KHz
    wait 1 second
    PWMOff
    wait 1 second
    
    HPWM 1,26,128 '26 KHz
    wait 1 second
    PWMOff
    wait 1 second
    
    HPWM 1,27,128 '27 KHz
    wait 1 second
    PWMOff
    wait 1 second
    
    HPWM 1,28,128 '28 KHz
    wait 1 second
    PWMOff
    wait 1 second
    
    HPWM 1,29,128 '29 KHz
    wait 1 second
    PWMOff
    wait 1 second
    
    HPWM 1,30,128 '30 KHz
    wait 1 second
    PWMOff
    wait 1 second
    

    goto Start

    Thanks again, Chip V.

     
  • Anobium

    Anobium - 2015-11-24

    Nice one!

    How do the rats like this?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.