Help with PWM6 and PWM7 on 16F18857 ???


Closed Thread
Results 1 to 9 of 9
  1. #1

    Default Help with PWM6 and PWM7 on 16F18857 ???

    Hello all,

    I'm trying to get PWM6 and PWM7 working on the 16F18857, and unfortunately these two are not accessible with the HPWM command. I've got them set to 50% duty cycle and I believe set to operate on the same timer (TIMER2) as the CCP HPWM peripherals, yet I get NADA when I look at the outputs. All the HPWM outputs (CCP 1-5) work as anticipated.

    It's not critical that the first timing period is accurate, so sloppy entry without an interrupt enabling at the end of a timing cycle period is fine.

    Any suggestions on what I've missed here?

    Thanks in advance for any brilliant ideas...



    'Using PIC16F18857

    DEFINE OSC 8 '8MHz
    OSCFRQ=$03

    TRISA=0 'all outputs
    ANSELA=0 '1=Analog, 0=Digital
    TRISB=0 'all outputs
    ANSELB=0 'all Digital
    TRISC=0 'all outputs
    ANSELC=0 'all Digital

    'PPS MODULE (Peripheral Pin Select)
    RA2PPS=$0E 'PWM6OUT OUTPUT on RA2
    RA3PPS=$0F 'PWM7OUT OUTPUT on RA3

    ' *** HPWM format as follows:
    'HPWM Channel, Dutycycle, Frequency

    HPWM 1, 0, 1000 '51/255 or 0% duty cycle pin 13
    HPWM 2, 102, 1000 '110/255 or 40% duty cycle pin 12
    HPWM 3, 153, 1000 '153/255 or 60% duty cycle pin 26
    HPWM 4, 204, 1000 '204/255 or 80% duty cycle pin 21
    HPWM 5, 127, 1000 '240/255 or 50% duty cycle pin 6

    ' Now, we need to select the same timer for PWM6 and 7 that is used for CCP1 (TMR2)
    CCPTMRS1=%00010101

    PWM6CON=%10010000 'enable and active high
    PWM7CON=%10010000 'enable and active high

    'set at 50% for both to test
    PWM6DCH=128:PWM6DCL=0 'PORTA.2 (pin 4)
    PWM7DCH=128:PWM7DCL=0 'PORTA.3 (pin 5)

    keepgoing:
    pause 500
    goto keepgoing

    end

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,380


    Did you find this post helpful? Yes | No

    Default Re: Help with PWM6 and PWM7 on 16F18857 ???

    using the code configurator [mcc] for a 16f18875
    yields the following settings , not unsimilar to yours. it works perfectly.
    maybe your pps is locked , your code is incomplete so I can't tell.

    1.5khz @32mhz fosc
    PWM6CON = $80;
    // DC 42;
    PWM6DCH = $2A;
    // DC 3;
    PWM6DCL = $C0;
    // Select timer
    CCPTMRS1.2 = 1
    CCPTMRS1.3 = 0
    // T2CS FOSC/4;
    T2CLKCON = 1;
    // T2PSYNC Not Synchronized; T2MODE Software control; T2CKPOL Rising Edge; T2CKSYNC Not Synchronized;
    T2HLT = 0;
    // T2RSEL T2CKIPPS pin;
    T2RST = 0;
    // PR2 85;
    T2PR = $55;
    // TMR2 0;
    T2TMR = 0;
    // T2CKPS 1:64; T2OUTPS 1:1; TMR2ON on;
    T2CON = $E0;
    RA2PPS = $0E; //RA2->PWM6:PWM6OUT;
    TRISA.2 = 0
    ANSELA = 0;
    Attached Images Attached Images  
    Last edited by richard; - 22nd January 2018 at 01:21.
    Warning I'm not a teacher

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Help with PWM6 and PWM7 on 16F18857 ???

    Actually that's ALL the Code... so I need to check the configuration word settings (I do this when prompted the programmer interface pops up) to ensure it's not locked, is that correct?

    I'm ignoring all the Timer2 config stuff because I'm going with the assumption that it's already set up to the correct period via the HPWM commands.

  4. #4
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Help with PWM6 and PWM7 on 16F18857 ???

    I personally have not had very good luck assuming anything. I tend to spell everything out as a matter of routine and habit. You might have to manipulate your PWM6/7 outputs manually with the PWM6/7DCH/L SFRs. Not that big of deal once you delve in and learn how. The data sheets are pretty concise about how it needs to be done. I would list the TMR2 SFRs just to be sure. Also, the default timer for ALL CCP and PWM functions is TMR2. There are a few things pertaining to PWM6/7 in the CCP section of the Data Sheet.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Help with PWM6 and PWM7 on 16F18857 ???

    Might be best to abandon using the CCP HPWM at the same time until I get PWM6/7 working, that way I can config the timer registers independently and know exactly what they are. I can break off and use TMR4 later if I find that CCP PWM interferes.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,380


    Did you find this post helpful? Yes | No

    Default Re: Help with PWM6 and PWM7 on 16F18857 ???

    There is no technical reason that prevents simultaneous pwm use of all the CCP and PWM modules with the same timer .
    I just made this example with mplabx/xc8 , it works exactly as expected.
    I cannot try it with pbp as my version does not support that chip
    Attached Images Attached Images  
    Warning I'm not a teacher

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Help with PWM6 and PWM7 on 16F18857 ???

    Good to know, thanks for the input!

    I've probably missed something simple, but still can't see it in my code snippet.

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: Help with PWM6 and PWM7 on 16F18857 ???

    Ok, thanks all for verifying approach. I found the issue to be that the resolution of the duty cycle in bits was 9, not 10, (it seems it varies with the PR2 value predetermined by the HPWM command), so with the MSB of the PWMxDCH set at 1 (PWM6DCH=128), the result was "always on" at the output, whereas I was anticipating a 50% duty cycle waveform.

  9. #9


    Did you find this post helpful? Yes | No

    Default Re: Help with PWM6 and PWM7 on 16F18857 ???

    Quote Originally Posted by picster View Post
    Ok, thanks all for verifying approach. I found the issue to be that the resolution of the duty cycle in bits was 9, not 10, (it seems it varies with the PR2 value predetermined by the HPWM command), so with the MSB of the PWMxDCH set at 1 (PWM6DCH=128), the result was "always on" at the output, whereas I was anticipating a 50% duty cycle waveform.
    Note that this was at 1KHz HPWM on CCP1 through 5. At 2KHz, you regain full 10 bit resolution again, according to my trials (using a clock speed of 8MHz).

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