HPWM outputs only on two channels on PIC16F886, when it should do more.
+ Reply to Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    Feb 2013
    Posts
    485

    Default HPWM outputs only on two channels on PIC16F886, when it should do more.

    Hello.

    PIC16F886 has 4 PWM channels. However, HPWM statement works only for first 2 - Ones at PortC. HPWM 0 outputs at PortC.2 and HPWM 1 outputs at PortC.1. However, HPWM 2 or HPWM 3 which are expected to output on the corresponding pins of PortB, do nothing. As I read from datasheet, CCP1CON register controls configuration of PortB PWM registers, but it gives no clue how it should be configured, so HPWM statement will work with these ports?

  2. #2
    Join Date
    Feb 2013
    Posts
    485

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    Have a little success - setting CCP1CON=%11000000 now HPWM 1 statement outputs on portb.2, but when issuing HPWM command, there's a small series of pulses on portc.1 and portc.2 pins, where I have LCD connected, so they disrupt LCD operation, weird characters appear on screen...

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    1,661

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    PIC16F886 has 4 PWM channels.
    no , it has only two ccp modules , ccp1 and ccp2 . ccp1 can have 4 outputs [p1A-D] in enhanced mode.
    ccp1 is on rc2 in pwm mode
    ccp2 is on rc1

    if ccp1 used in enhanced single output mode you can use output steering to direct output to rb1 rb2 rb4 or rc2
    i doubt if hpwm command supports enhanced mode
    This is more entertaining than Free to Air TV

  4. #4
    Join Date
    Feb 2013
    Posts
    485

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    tried adding FLAGS=0 after sending HPWM, LCD becomes blank...

  5. #5
    Join Date
    Feb 2013
    Posts
    485

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    I did it!

    CCP1CON=%00000000 ' configure pwm
    PSTRCON=%00011110 'disable C pwm

    This config disables PWM output on PortC, but it is now enabled on PORTB.2 and PORTB.4, so HPWM statement now control PortB pins, instead of PortC

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    1,661

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    CCP1CON=%00000000 ' configure pwm
    is useless and wrong anyway.

    PSTRCON=%00011110 'disable C pwm

    This config disables PWM output on PortC, but it is now enabled on PORTB.2 and PORTB.4, so HPWM statement now control PortB pins, instead of PortC
    and rb1 too if its tris bit is cleared

  7. #7
    Join Date
    Feb 2013
    Posts
    485

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    without that CCP1CON, HPWM statement still controls PortC, not B. Have no idea how it is related, but achieved result thru trial and error. And for PSTRCON, This PSTRCON=%00010110 will output into single pin.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    1,661

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    And for PSTRCON, This PSTRCON=%00010110 will output into single pin.
    no it won't . read the datasheet
    without that CCP1CON, HPWM statement still controls PortC, not B. Have no idea how it is related
    to enable pwm mode ccp1con must = 12 . the hpwm command if used will set it to 12 regardless of what you have previously set .
    i would examine the lst file to confirm the PSTRCON settings are not interfered with by a hpwm command .


    just had a look at a lst file,
    even if you set the defines correctly it will not set pstrcon, it will set the tris ok. it always overwrites ccpxcon
    Code:
    DEFINE CCP1_REG PORTB 'Channel-1 port
    DEFINE CCP1_BIT 2 'Channel-1 bit
    
    hpwm 1 , 128,8000
    
    lst
    002A   0817           02148         movf    CCP1CON, W      ; Get ready to set CCPCON
    002B   39CF           02149         andlw   0cfh            ; Clear bottom 2 CCP bits
    002C   1BA4           02150         btfsc   R2, 7           ; Set bottom 2 CCP bits
    002D   3820           02151         iorlw   20h             ; Set bit 5
    002E   1B24           02152         btfsc   R2, 6
    002F   3810           02153         iorlw   10h             ; Set bit 4
    0030   380C           02154         iorlw   0ch             ; Set PWM mode
    0031   0097           02155         movwf   CCP1CON         ; Finally set CCPCON
    0032   0825           02156         movf    R2 + 1, W       ; Set top 8 CCP bits
    0033   0095           02157         movwf   CCPR1L
    0034   1683           02158         bsf     STATUS, RP0     ; Point to TRIS
    0035   1106           02159         bcf     CCP1_REG, CCP1_BIT      ; Set CCP1 to output
                          02160
    Attached Images Attached Images  
    Last edited by richard; - 14th April 2019 at 13:57.
    This is more entertaining than Free to Air TV

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    1,661

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    i'm not quite right
    hpwm will "set" bits 2,3,4,5 the rest of the bits are preserved, but bit 6,7 must be 0 for pwm and bits 0,1 affect pwm polarity in eccp mode
    This is more entertaining than Free to Air TV

  10. #10
    Join Date
    Feb 2013
    Posts
    485

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    Saying shortly, my code works as it should HPWM is where it should be, LCD is crystal clear display

  11. #11
    Join Date
    Feb 2013
    Posts
    485

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    Back to basics, is it possible, using mainly picbasic statements, to make chips with 4 channel pwm to output 4 pwm signals, with same frequency and duty ratio, but shifted with a dead band between each step? As I can understand from datasheet of 16F886, it is possible for 2 outputs, not for 4, am I right?

  12. #12
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    289

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    I think I know what you're asking; 4 individual PWM outputs, same DC%, same freq. One initiates, then a time frame later the second goes high, a pause then the 3rd goes high, then after another dead-band delay the last one goes high. They would then sequentially go low with the same delay value. Am I understanding correctly?

    This can be done with CLC (Configurable Logic Cell) and Timers 2/4/6. The first PWM fires directly. The 2nd is muxed with Timer 2 through a CLC AND circuit. The 3rd is muxed with Timer 4, and finally the last with Timer 6. This will bring them on sequentially, and ultimately all 4 will be high at the same time and low at the same time during certain portions for the period. With HLT (in TMR2/4/6) in One-Shot Mode, the Timers can be triggered ON and OFF automatically using the PWM signal. Quite a complex method I must admit.

    Still working on how to turn the PWMs off sequentially, but you got a thought process started.
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  13. #13
    Join Date
    Feb 2013
    Posts
    485

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    Well I need a sequence like one used to control steppers, but with some delay between pulses on each line, so say D0 went low, but there's small delay, before D1 becomes high and so on: https://wiki.analog.com/_detail/univ...stepper-motors

  14. #14
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    289

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    Check out the PIC16F157X. It has 16-bit PWM with phase control and 4 channels. It sounds close to perfect for you.
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  15. #15
    Join Date
    Feb 2013
    Posts
    485

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    Thanks, will check.

    Another question, is it possible to generate interrupt on hpwm pulse fall? Say, D0 becomes low - interrupt is generated, D1 becomes low - again, and so on.

  16. #16
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    289

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    You can feed PWM into a CLC and use the CLC interrupt. On the PIC16F1578, you have quite a list of interrupts tied to the PWM. There's 2 options for you.
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  17. #17
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    289

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    Another one with 16-bit PWM is the PIC16F17xx series. The PIC16F1778_9 even has 12-bit ADC.
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  18. #18
    Join Date
    Feb 2013
    Posts
    485

    Default Re: HPWM outputs only on two channels on PIC16F886, when it should do more.

    Good, I'm considering making a nixie clock, with this, "semi-hardware" multiplexing, so PWM outputs will drive anodes, and on interrupt, cathodes will get the proper display....

Similar Threads

  1. HPWM with Pic16F886 not working
    By lerameur in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2014, 03:24
  2. Replies: 6
    Last Post: - 28th April 2012, 01:42
  3. 3 HPWM channels with PIC18F26K20
    By pxidr84 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th January 2011, 17:58
  4. pic16f886
    By NURULHAIZA in forum General
    Replies: 5
    Last Post: - 21st May 2010, 08:09
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43

Members who have read this thread : 18

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts