18f4680 pwm


Closed Thread
Results 1 to 3 of 3

Thread: 18f4680 pwm

  1. #1

    Question 18f4680 pwm

    Hello,

    I am trying to use the ECCP for a full H-bridge. I can not seem to get it working, any help would be appreciated in resolving my issue... see below.


    Code:
           	INCLUDE "Modedefs.Bas"    
     	DEFINE OSC 20
    
     		
    ; Set port direction and turn off unused peripherals
            CMCON  = 7          			' shut offcomparators
            TRISA = %00011111				' Set PORTA to input "1" or output "0"
            TRISB = %00000000    			' set portB to output "0" or input "1"
            TRISC = %00000000
            TRISD = %00000000
            TRISE = %00000000
            
            ADCON1 = %00001111				' bit 0 ~ bit 3 sets ports as digital I/O. 1 = digital, 0 = analog
            ADCON0 = %00000000              ' bit 0 disables A/D converter module.
            ECCP1CON = %00000000            ' bit 0 ~ bit 3 turns off capture/compare/PWM
            
            
    ; Declare variables and aliases
    
    duty var byte
    
    PAA var LATA
    PBB var LATB
    PCC var LATC                             
    PDD var LATD                          ' used to re/set portD.1, can not use portd.1 = x on latch ports
    PEE var LATE
    
    
    ; initialize power on state of ports
    LATA = 0
    LATB = 0
    LATC = 0
    LATD = 0                                ' force latches on portD to low
    LATE = 0
    
    
            ECCP1CON = %11001100            ' bit 0 ~ bit 3 turns off capture/compare/PWM
            T2CON = %00010101		         ' Turn on Timer2, Prescale=4
            PR2 = 249				         ' Set PR2 to get 5KHz PWM out
             
            duty = 100                      
            ECCPR1L = DUTY
            ECCP1CON.4 = duty.0		            
            ECCP1CON.5 = duty.1		            
                   
             
    Mainloop:
            
           pauseus 1000
             
          goto mainloop

  2. #2


    Did you find this post helpful? Yes | No

    Default works

    It works as is.... traces lifted off PCB...

  3. #3
    Join Date
    Jan 2010
    Location
    PHILADELPHIA, PA - USA
    Posts
    34


    Did you find this post helpful? Yes | No

    Default 10 bits duty cycle

    I played with this code a little today and it works well....Thanks

    Just a few minor changes can give 10 bits PWM resolution.

    Change duty var byte to duty var word.

    Add the line ECCPR1L = duty >> 2 after ECCP1CON.5 = duty.1.

    now the duty cycle can be set from 0 to 1023 instead of 0 to 255.

    Bob W.
    Wozzy-2010

Members who have read this thread : 1

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