--- This is a test - only visible to admins ---
--- advertisement may go here ---
  • 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
  • Recent Activity

    xldaedalus-432

    Mysterious PORTB problem

    Thread Starter: xldaedalus

    I'm using Proton+ to develop firmware for a product with switches. The MCU is an 18F26K22. Most of the switches reside on PORTB. I am NOT using a...

    xldaedalus Yesterday, 18:21 Go to last post
    Les-15

    Pic16f18877 oread

    Thread Starter: evoortman

    Hi, On a PIC16F18877 the OREAD command doesn't seem to work. The code is working on a PIC16F1939. Both controllers use 32MHz int osc. If i...

    Les Yesterday, 13:05 Go to last post
    amod-29593

    Multiple functions by a single switch

    Thread Starter: amod

    Hi, How can I use multiple function by a single switch.I want to use 4 functions by a single switch.

    amod Yesterday, 15:31 Go to last post
    Oldhack-15978

    FUSES for PIC18F47K20

    Thread Starter: gtv_pic

    000 Good morning I am using the PIC18F47K20 and in the help of the proton I did not locate the FUSES for said micro. Where can I locate...

    Oldhack Yesterday, 16:34 Go to last post
    Les-15

    SHIN generates ASM ERROR with the 16F18877

    Thread Starter: evoortman

    Hi, On a PIC16F18877 the SHIN command generates an ASM ERROR: Could this also be related to renamed or moved SFRs in the newer controllers? ...

    Les Yesterday, 19:18 Go to last post