• 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.

    Code:
    ; 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) 
    
    Ch_on1:
    BCD_CD4051 = %00000000  ; CD4051 Ch 1
    GoSub BCD_OUT
    HPWM 1, pwm, 2000       ; at 2kHz (or lower)  
    ;
    
    Ch_off1:
    HPWM 1, 0, 2000
    High Inhibit             ; CD4051 output disable PORTC.5
    ;
    ;
    Ch_on2:
    BCD_CD4051 = %00000001  ; CD4051 Ch 2
    GoSub BCD_OUT
    HPWM 1, pwm, 2000       ; at 2kHz (or lower)  
    ;
    
    Ch_off2:
    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
    Return
    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.

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