Pwm 16f876a


Closed Thread
Results 1 to 9 of 9

Thread: Pwm 16f876a

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382

    Default Pwm 16f876a

    I recently moved a project from a 16F88 to the 16F876A to gain more I/O. Previously the contrast of the LCD was controlled via PWM on CCP1, which worked perfectly. Since moving to the larger PIC I added PWM control of the backlight and can't get either to work.

    I have set everything up the same way and have all the defines correct. I have reread Melanie's post about backlight and contrast control. I have no clue where I'm going wrong. Help?


    ; -----[ Fuses ]----------------------------------------------------------
    @__config _HS_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF

    ; -----[ Setup ]----------------------------------------------------------
    ADCON1=%10000110 ; Turn on A/D AN0 - Digital for the rest (16F876A specific)
    CMCON=%00000111 ; Disable Comparators
    TRISA=%11100001 ; PORTA Output/Input settings (1= Input 0=Output)
    TRISB=%00000001 ; PORTB Output/Input settings (1= Input 0=Output)
    TRISC=%10001000 ; PORTC Output/Input settings (1= Input 0=Output)
    OPTION_REG.6=1 ; INTEDG rising edge=1 falling edge=0
    T1CON.4=1
    T1CON.5=1

    ; -----[ Defines ]----------------------------------------------------------
    DEFINE OSC 20 ; 20 mhz XTAL (change notes above)
    DEFINE I2C_SLOW 1

    DEFINE HSER_BAUD 9600 ; 9600 Baud USART
    DEFINE HSER_RCSTA 90h ; Enable USART RX
    DEFINE HSER_TXSTA 24h ; Enable USART TX
    DEFINE HSER_SPBRG 51 ; 9600 Bauds
    DEFINE HSER_CLROERR 1 ; Clear all USART errors as they happen

    DEFINE LCD_DREG PORTB ; LCD 20x2
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 3
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50

    DEFINE CCP1_REG PORTC ; HPWM 1 pin port
    DEFINE CCP1_BIT 2 ; HPWM 1 pin bit
    DEFINE CCP2_REG PORTC ; HPWM 2 pin port
    DEFINE CCP2_BIT 1 ; HPWM 2 pin bit

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what happen if you remove
    Code:
    DEFINE CCP1_REG PORTC ; HPWM 1 pin port
    DEFINE CCP1_BIT 2 ; HPWM 1 pin bit
    DEFINE CCP2_REG PORTC ; HPWM 2 pin port
    DEFINE CCP2_BIT 1 ; HPWM 2 pin bit
    Since this PIC don't have alternate pin for any CCPx, i don't know how it's handled.

    And the obvious, if i can... did you really selected the right PIC in the editor?

    Also, you should have a space between @ and __Config. But it could be a forum copy/paste problem so..

    Also, even if not PWM related
    Code:
    DEFINE HSER_BAUD 9600 ; 9600 Baud USART
    DEFINE HSER_RCSTA 90h ; Enable USART RX
    DEFINE HSER_TXSTA 24h ; Enable USART TX
    DEFINE HSER_SPBRG 51 ; 9600 Bauds
    DEFINE HSER_CLROERR 1 ; Clear all USART errors as they happen
    You have two definition of the Baudrate... one is false. Or you keep HSER_BAUD 9600 or you correct the HSER_SPBRG 51 to HSER_SPBRG 129. 51 is the right value for 8MHZ.
    Last edited by mister_e; - 19th September 2006 at 05:58.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    If I remove the defines I get the same results, which is nothing.

    And yes, 16F876A for CodeDesigner Lite & ICProg.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm how about the frequency? @20MHZ the minimum should be 'round 1.2KHZ if you're using HPWM.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Here are the subs I'm using.

    ; -----[ LCD Contrast PWM ]-----------------------------------------
    PWM_Contrast:
    value=Contrast*40
    HPwm 1,value,1000
    Return

    ; -----[ LCD Backlight PWM ]----------------------------------------
    PWM_BackLight:
    value=Backlight*51
    HPwm 2,value,1000
    Return

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    As i said, the minimum frequency should be 1.2Khz. 1.3KHZ work fine here. So change it to...

    Code:
    -----[ LCD Contrast PWM ]-----------------------------------------
    PWM_Contrast:
    value=Contrast*40
    HPwm 1,value,1300
    Return
    
    ; -----[ LCD Backlight PWM ]----------------------------------------
    PWM_BackLight:
    value=Backlight*51
    HPwm 2,value,1300
    Return
    About now?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 07:24
  4. 16f876a Pwm
    By Hainkm in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th December 2007, 17:33
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 00:26

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