Proton BASIC Compiler - Re: PIC with upto 8 (alt.) HPWM channels extra

  • PicŪ Basic

  • PIC with upto 8 (alternating) HPWM extra channels

    I needed 6 channels extra besides the standard built-in HPWM of the PIC. I knew that a standard CMOS Muxer, can fulfill this.

    The only disadvantage is that 1 channel at-a-time can be selected, but that was not a problem (in my case).

    So I toke one CD/HEF4051 connect the Inhibit and the 3 ABC (e.g. BCD) lines to the PIC free ports.

    Rewrote my program a bit, tested, and it works just fine.

    With HPWM frequency of 2000Hz this is not a problem for the 4051, and for low-power applications.

    ; BCD_CD4051 BCD table   ; CD4051 ABC resp. pin 11-10-9 (MSB to LSB)
    ; BCD_CD4051 = %00000000 ; CD4051 Ch 1
    ; BCD_CD4051 = %00000001 ; CD4051 Ch 2 
    ; BCD_CD4051 = %00000010 ; CD4051 Ch 3
    ; BCD_CD4051 = %00000011 ; CD4051 Ch 4
    ; BCD_CD4051 = %00000100 ; CD4051 Ch 5
    ; BCD_CD4051 = %00000101 ; CD4051 Ch 6
    ; BCD_CD4051 = %00000110 ; CD4051 Ch 7
    ; BCD_CD4051 = %00000111 ; CD4051 Ch 8
    ; HPWM out to Pin 3 of CD4051
    ; Low  Inhibit ; output enable  eq. PORTC.5 or any other port
    ; High Inhibit ; output disable eq. PORTC.5
    Symbol Inhibit   = PORTC.5    ; to CD4051 pin 6
    pwm = 127       ; 50% or wathever you choose
    ;from Goto or GoSub (whatever) 
    BCD_CD4051 = %00000000  ; CD4051 Ch 1
    GoSub BCD_OUT
    HPWM 1, pwm, 2000       ; at 2kHz (or lower)  
    HPWM 1, 0, 2000
    High Inhibit             ; CD4051 output disable PORTC.5
    BCD_CD4051 = %00000001  ; CD4051 Ch 2
    GoSub BCD_OUT
    HPWM 1, pwm, 2000       ; at 2kHz (or lower)  
    HPWM 1, 0, 2000          ; The "Ch_off" are all the same, so you can even invoke GoSub, if you like.  
    High Inhibit             ; CD4051 output disable PORTC.5
    ;Repeat this for the next channels, the only differences are BCD_CD4051 bit's, and the Ch x names.
    ; GoSubs section  
    BCD_OUT:                  ; BCD to Port (PORTB as example)
    PORTB.6 = BCD_CD4051.2    ; A pin 11 4051 
    PORTB.5 = BCD_CD4051.1    ; B pin 10 
    PORTB.4 = BCD_CD4051.0    ; C pin  9
    Low Inhibit               ; output enable  PORTC.5
    For more information on the 4051 just Google `CD4051' for the datasheet.

    Do not forget to connect pin 7 and pin 8 to VSS, (e.g. ground), and pin 16 to VDD (e.g. +5v).

    The rest of the pin's is documented in the code.
    How you arrange the channels out from the 4051 is up to you.

    This article was originally published in forum thread: PIC with upto 8 (alt.) HPWM channels extra started by Henk57 View original post
  • Recent Activity


    Valid time in NMEA sentance

    Thread Starter: SimonJA

    Is there any way to know that a GPS nmea sentence has the correct time? I use a module to keep a pic rtc accurate but have noticed that when...

    joesaliba Today, 16:30 Go to last post

    I'm over the moon with joy. :-)

    Thread Starter: Les

    I just had to show you this, because I am over the moon with it. LOL I've just about finished procedures on the Proton 8-bit compiler so I am busy...

    towlerg Today, 16:13 Go to last post
    John Drew-26

    GPS speed logger for RC planes.

    Thread Starter: david

    Hi All, This is a simple project to allow the logging of RC plane speeds to help determine battery, motor and prop variables. The code is crude and...

    John Drew Today, 01:31 Go to last post