How to make HPWM slower with 16F887?


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: How to make HPWM slower with 16F887?

    Using a PIC there's no better way than using the (E)CCP module in PWM-mode - no.

    Using the HPWM command to "drive" the (E)CCP module in PWM-mode may not be ideal as have been described but it will work as a starting point. If you want to drive the ECCP module manually there's another thread active right now which discusses just that and there's a lot of info burried in the forum.

    And, as have been said a couple of times now, you DON'T want to make the PWM output "slower", you want to slow down the rest of the program. It's not the PWM frequency that determines the "dimming speed" it's how often you update the dutycycle.

    /Henrik.

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: How to make HPWM slower with 16F887?

    Basically you need a frequency fast enough so that the eye doesn't detect it, and a smooth ramp up / down in duty cycle over a 4 minute period.

    The problem is that with just 255 steps between 0% and 100% you will notice the stepping in brightness at low levels, such as when the value is in single figures. For smooth dimming you need 4096 steps. One solution would be to use an PCA9685 chip which has 16 PWM outputs, each with 4096 steps, and is controlled via I2C bus.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: How to make HPWM slower with 16F887?

    The problem is that with just 255 steps between 0% and 100% you will notice the stepping in brightness at low levels
    most pics have 10 bit pwm and if used the "stepping" effect is negligible , why not to use the 1024 steps


    here is a simple demo with the led on portc.5 "stepping" at low levels even when gamma corrected

    the led on portc.3 is as smooth as silk


    Code:
    '****************************************************************
    '*  Name    : fader.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 6/30/2016                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :  pic16f1825                                                 *
    '*          :                                                   *
    '****************************************************************
     
       
    #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
     
     
    DEFINE OSC 32 
     
     
     
    goto overpwm 
     
     my_pwm:  
    ;100 step 1.35 gamma curve   
    @ dW   1,  1,  1,  1,  1,  1,  1,  1,  1,  1
    @ dW   1,  1,  1,  1,  1,  1,  2,  2,  2,  2
    @ dW   2,  2,  2,  2,  2,  3,  3,  3,  3,  3
    @ dW   3,  4,  4,  4,  4,  5,  5,  5,  6,  6
    @ dW   6,  7,  7,  8,  8,  9,  9, 10, 11, 11
    @ dW  12, 13, 14, 15, 16, 17, 18, 20, 21, 23
    @ dW  24, 26, 28, 30, 33, 35, 38, 41, 44, 47
    @ dW  51, 55, 59, 64, 69, 74, 80, 86, 93,101
    @ dW 109,118,128,138,150,162,176,190,206,224
    @ dW 243,263,286,310,337,366,398,433,471,511
     
     
    
    ASM
    ;---[Returns the Address of a Label as a Word]------------------------------
    GetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
    ;    movlw High Label         ; get high byte  MPLAB 8.53 killed high
        movlw Label >> 8         ; get high byte
        movwf Wout + 1
      endm
    endasm
    overpwm:
     
       OSCCON=$70
       ANSELA=0
       ANSELC=0
       paddress var word
       pw       var word
       pl       var byte
       pl2       var word
       inc var word
       t2con=5 
       TRISA = %111110
       TRISC = %11010011         ' set PORTC I/O
       led1 var portc.3       ; 10 bit straight pwm
       led2 var portc.5        ; 10 bit 100 step gamma corrected pwm
     
     
    @ GetAddress _my_pwm,_paddress 
    pl2 =0  
    pl=100 
      
    main:
    inc=1   
    while pl
        pl=pl-1
        gosub setpwm
        pause 50
    wend
    inc=-1
    while pl < 99
         pl=pl+1
         gosub setpwm
        pause 50
    wend
    goto main
    
     setpwm:
        readcode paddress+pl ,pw
        CCPR1L = PW>>2;
        ccp1con=12|((PW&3)<<4);     led2
        pl2 =pl2 +inc
        if pl2 >1023 then pl2 =0 
        CCPR2L = Pl2>>2;            led1 
        ccp2con=12|((Pl2&3)<<4);
    return
    Warning I'm not a teacher

  4. #4
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: How to make HPWM slower with 16F887?

    Richard, I can't help but notice your table only goes to 511. That's half of the available pwm pulse width.
    Dave Purola,
    N8NTA
    EN82fn

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: How to make HPWM slower with 16F887?

    I can't help but notice your table only goes to 511. That's half of the available pwm pulse width.
    that's correct dave.
    The point was to demonstrate that its possible to eliminate the visible brightness steps that are most evident at the dimmest fading levels. The steps are quite visible at the lowest 20 or so pulse widths wether its gamma corrected at full 10 bit resolution or linear at 8 bit resolution .
    100 steps was all that's necessary to prove the point , it can be done

    the missing 10 steps
    100 481
    101 522
    102 568
    103 617
    104 671
    105 729
    106 793
    107 863
    108 940
    109 1023
    Warning I'm not a teacher

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: How to make HPWM slower with 16F887?

    Thanks so much for the help. I'll give this a try.

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: How to make HPWM slower with 16F887?

    If it helps for a musical instrument you can connect an old AM radio tuning capacitor across one of the crystal capacitors or across the crystal itself,
    and bend the note a little. Of course you don’t have programatic control over that manual knob, but you do have infinite resolution over a range.

Similar Threads

  1. Can't make RA1 a digital Input on (10 out of 20) 16F887.
    By paulgrut in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 11th October 2013, 06:53
  2. USB HID is slower than often using PIC18f2550
    By Ahmadabuomar in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th November 2010, 14:05
  3. Mibam at 20mhz runs slower than at 4 mhz
    By Homerclese in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st October 2010, 18:41
  4. Code running 19 times slower than intended
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 15th April 2010, 12:20
  5. Servo Slower?
    By actionplus in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 4th September 2004, 13:56

Members who have read this thread : 0

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