Pwm settings for 18f47k40


+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    792

    Default Pwm settings for 18f47k40

    hi guys have anyone got set an example for this on the 18f47k40

    looking to put PWM4 using timer 2 on port c.1


    tryied using

    define HPWM4_TIMER 2 ' HPWM4 TO USE TIMER 2 - USED FOR HUB_OE DIMMING CONTROL
    RC1PPS = $08 ' SET PWM4 TO PORTC.1
    tris portc.1 =0
    PMD1.2 = 0 ' allow timer 2
    PMD3.3 =0 , allow PWM4

    hpwm 4 ,PWM_Duty ,1000 'CPP4 Wduty , freq

  2. #2
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    282

    Default Re: Pwm settings for 18f47k40

    The "HPWM" Command only works with CCPx Modules, not PWMx. This should get you functional:

    Code:
    #CONFIG
     CONFIG PPS1WAY = OFF                ;PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
    #ENDCONFIG
    
    
    Value       VAR     BYTE
    
    
    Init:
    ;   -=- NOTE: This is merely example code.  There are no SFRs for OSC and other Important Registers!! -=-
    
    
        TRISC.2 = 1                     ;Initialize PWM4 Output as an Input, will change later
        ANSELC.2 = 0                    ;Make PWM4 Output Digital
        PIE4.1 = 0                      ;Ensure TMR2 Interrupt is Disabled
        PIR4.1 = 0                      ;Clear TMR2 Interrupt Flag
        
    ; -=- NOTE: Section 20 of the Data Sheet Covers Pre/Post Scalers for Timer 2 -=-
        T2CON = %00100000               ;1:4 Prescaler, note ON = 0
        T2CON.7 = 1                     ;Turn Timer 2 ON in Separate Operation
        WHILE PIR4.1 = 0                ;Wait Until Timer2 is Running
        WEND
        PIR4.1 = 0                      ;Timer 2 is Now Running
        TRISC.2 = 0                     ;Now Change RC2 to Output
        PPSLOCK = $55                   ;Peripheral Pin Select
        PPSLOCK = $AA                   ; Unlock Sequence
        PPSLOCK.0 = 0                   ; PPS = UNLOCKED
        RC2PPS = $08                    ;PWM4 Output on RC2
    ; -=- NOTE: You can Lock PPS when you're done (Optional, but Recommended)
        PPSLOCK = $55                   ;Peripheral Pin Select
        PPSLOCK = $AA                   ; Unlock Sequence
        PPSLOCK.0 = 1                   ; PPS = LOCKED
        PWM4DCL = 0
        PWM4DCH = 100                   ;THIS IS YOUR DUTY CYCLE REGISTER, 0 >> 255 (8-bit)
        PWM4CON = $80                   ;Turn PWM4 ON
        
    Main:
    DO
        'GOSUB Get_PWM4                 ; -=- Determine Value for PWM4 DC%
        PWM4DCH = Value
        LOOP

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    792

    Default Re: Pwm settings for 18f47k40

    thanks mike

Similar Threads

  1. Replies: 1
    Last Post: - 4th March 2013, 21:57
  2. 18F4580 settings
    By malc-c in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 27th March 2010, 15:59
  3. Confused over A/D settings
    By malc-c in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd February 2010, 10:44
  4. Help with code, settings
    By xobx in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th September 2007, 00:31
  5. Changing Settings ???
    By tico in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th December 2006, 03:10

Posting Permissions

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