Menu

Complementary Output Generator (COG)

2017-05-25
2017-05-25
  • David Stephenson

    I've been looking at the datasheet for the 16F1705 and controlling this module at first (and even second) look is daunting - just so many options in so many registers. Anyway many of these setting are not on closer examination relevant to getting the thing working. So I've managed to take the PWM3 output (set to 40kHz and 50% duty cycle) and feed it into the COG module to output two complimentary waveforms (on RC4 and RC5). I intend to drive an ultrasonic tranducer using the square wave from these two pins.
    Below is the code it may get you started if you feel to use this module.

    ~~~~~~~~

    chip 16LF1705,8

    config OSC=INTOSC, MCLRE=Off, WDT=off, boren=off

    unlockpps
    RC5PPS = 8 'coga > RC5
    RC4PPS = 10 'COGC>RC4
    lockpps

    INIPWM3
    INICOG

    do
    wait 5 sec
    SET COG1ASD0.7 OFF
    wait 5 sec
    SET COG1ASD0.7 ON
    loop

    SUB INIPWM3
    ccptmrs=b'00000000' 'select timer2 for all
    pwm3con=b'00000000' 'clr reg
    pr2=49 'set period 40 kHz
    pwm3dch=25 '100 ->50%
    pwm3dcl=0 'set duty cycle
    pir1.1=0 'clr interrupt timer2
    t2con=b'00000100' 'start timer
    dir portc.5 out 'enable PWM pin
    set pwm3con.7 on 'enable PWM3
    END SUB

    SUB INICOG
    'INITIALIZE COG FOR HALF BRIDGE OUTPUT
    'ON CHANNELS COGA AND COGC USING PWM3
    SET PWM3CON.7 OFF 'DISABLE PWM
    dir portc.5 in 'disable COG pin
    DIR PORTC.4 IN
    COG1CON0=B'10001100' 'ENABLE,FOSC,HALF BR
    COG1DBR=0 'NO RISING DELAY
    COG1DBF=0 'NO FALLING DELAY
    COG1CON1=B'00000001' 'POLARITY COGA REVERSED
    COG1BLKR=0
    COG1BLKF=0
    COG1PHR=0
    COG1PHF=0
    COG1ASD1=0
    COG1ASD0=B'10001000' 'COG OFF A&C OFF
    SET COG1RIS.6 ON 'PWM3 SOURCE
    SET COG1FIS.6 ON 'PWM3 SOURCE
    COG1RSIM=0
    COG1FSIM=0
    DIR PORTC.5 OUT
    DIR PORTC.4 OUT
    SET COG1ASD0.7 OFF 'COG ENABLE
    SET PWM3CON.7 ON 'ENABLE PWM
    END SUB

    ~~~~~~~~~

     
  • stan cartwright

    stan cartwright - 2017-05-26

    Is the idea to give the us transducer more output? I've seen 555 circuits that use push-pull to drive us tx,

     
  • David Stephenson

    Yes thats the idea I'm using 2xAA batteries so there's not a lot of voltage to work with.
    The receiver is picking it up remarkably well so I may not have to use much amplification.
    My goal is to make an ultrasonic anemometer.

     
  • stan cartwright

    stan cartwright - 2017-05-26

    Good on you sir,very not my thing but nice you picked GCB as a dev option. Thanks for the code, it is pasted for future ref. Anti phase square wave is 4 times more I read.Like a 12v car amp that gives more than 3W. Intrigued about your project I can only say I spent a lot of time many years ago building the reciever end for us sensors and it never worked.. alas. I still have 2 sets of matched sensors...neither is called tx or rx. Those ebay sensors are very good since they are a rip off of a pic circuit,like the one I tried to get working on vero
    edit anemometer? half spheres windmill?
    edit 2 the speed of wind...yes,sounds brill but in reality...us sensor??? ok they work at the speed of sound and wind isn't that fast so....???

     

    Last edit: stan cartwright 2017-05-26

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.