• AVR Freaks

Hot!High Frequency PWM using PIC16F15323

Author
Ravikiran_H
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2020/03/20 05:14:34
  • Location: 0
  • Status: offline
2020/03/27 06:06:30 (permalink)
0

High Frequency PWM using PIC16F15323

HI Guys ,i am using a MPLABX to program the PIC16F15323 ic, i using MCC plugin to configure the ic. i am able to get the high frequency PWM but i am getting the actual PWM frequency is 4-5 times less than the configured PWM frequency. And also i want a smooth control over the PWM control. if any body know what may be problem. Please give me the solution.
Thank you
#1

10 Replies Related Threads

    mpgmike
    Super Member
    • Total Posts : 438
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: online
    Re: High Frequency PWM using PIC16F15323 2020/03/27 06:42:55 (permalink)
    +5 (5)
    Possibly your Fosc settings, perhaps your TMR2 Pre/Post scaler.  It's probably in line 42 of the code you haven't posted.

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #2
    Howard Long
    Super Member
    • Total Posts : 796
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: High Frequency PWM using PIC16F15323 2020/03/27 07:23:02 (permalink)
    +2 (2)
    mpgmike
    Possibly your Fosc settings, perhaps your TMR2 Pre/Post scaler.  It's probably in line 42 of the code you haven't posted.




    It would also help if we knew what PWM frequency the OP is after, and what their definition of "smooth control" is. But my telepathy skills aren't what they once were.
    #3
    mpgmike
    Super Member
    • Total Posts : 438
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: online
    Re: High Frequency PWM using PIC16F15323 2020/03/28 07:34:04 (permalink)
    +2 (2)
    Sent my crystal ball out for a polishing.  Now because of this virus thing, I can't get it back.  

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #4
    Ravikiran_H
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2020/03/20 05:14:34
    • Location: 0
    • Status: offline
    Re: High Frequency PWM using PIC16F15323 2020/04/01 05:59:03 (permalink)
    0
    check the code and attached file below and tell me what may be problem in that.
    this is code written inside the while loop
     
    for (int i = 0; i < 200; i++) {
    uint16_t dutyValue = i;
    PWM3DCH = (dutyValue & 0x03FC) >> 2;
    // Writing to 2 LSBs of PWM duty cycle in PWMDCL register
    PWM3DCL = (dutyValue & 0x0003) << 6;
    // PWM3DCL = 0x064;
    delay(100);
    }
     

    Attached Image(s)

    #5
    mlp
    boots too small
    • Total Posts : 936
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: High Frequency PWM using PIC16F15323 2020/04/01 11:40:18 (permalink)
    +1 (1)
    Ravikiran_H
    check the code and attached file below and tell me what may be problem in that.

    The code shown is not a complete compilable sample, for a start.
     
    It does not show your config bits.
    It does not show what options you specified to the compiler.
    We can't reproduce whatever symptom you might be seeing.
     

    Mark (this opinion available for hire)
    #6
    Ravikiran_H
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2020/03/20 05:14:34
    • Location: 0
    • Status: offline
    Re: High Frequency PWM using PIC16F15323 2020/04/03 20:16:44 (permalink)
    0
    Hi guys ,thanks for your reply...! i have attached a project file below. Please check it and Let me know ,what may be the Problem.
    Thank you.
    #7
    davekw7x
    Entropy++
    • Total Posts : 1880
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: High Frequency PWM using PIC16F15323 2020/04/04 10:41:55 (permalink)
    +2 (2)
    Ravikiran_H
    ...have attached a project file...



    Pardon me for coming to the party late, but I was waiting for some code so that I could try to help you get to the bottom of things rather than try to guess.  See Footnote.
     
    I looked at your configuration and connected a 20 MHz external oscillator to CLKIN on pin 2.  I connected a 'scope on PWM3OUT on pin 5.
     
    I saw 100 KHz PWM starting at 100% duty cycle then sliding to zero where it stayed for "a little while," then started at max again.  It went through this repeatedly.
     
    I think that is reasonable, given your program.  Maybe not what you had in mind, but the bottom line is that with proper clock input you should be able to see some output and, maybe, go from there to debug your code and maybe even get something useful from an application using PWM3.
     
    Suggestion: For your own debugging of PWM3 and to give others a chance of helping, I would use internal clock.  That way, you eliminate any possible external clock or clock connection problems, and people without an easy way to apply an external 20 MHz clock can be in a position to test and offer explicit help.
     
    Tested with an external 3.3V power supply on my PIC16F15323 (DIP-14) solderless breadboard with an external 3.3V CMOS clock generator.
     
    MPLABX version 5.35, XC8 version 2.10 (C99 mode), SNAP programmer.
     
    I made no changes in any part of your code.  The only project settings that I changed were to use my SNAP programmer rather than the PICkit3 that I think you used.
     
    Regards,

    Dave
    Footnote: My guess would have been some hardware problem.  Either with the clock or with some other connection problem (bypass capacitors, reset connection, power, etc...)  Personally I never waste a single New York minute on a project unless and until I can verify proper clock operation.  It really makes no sense to try to debug PWM or anything else unless the clock is what I think it should be.  (Toggle an LED in a loop with __delay_ms(1000) or some such thing.)
    post edited by davekw7x - 2020/04/04 10:57:15

    Sometimes I just can't help myself...
    #8
    Ravikiran_H
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2020/03/20 05:14:34
    • Location: 0
    • Status: offline
    Re: High Frequency PWM using PIC16F15323 2020/04/06 00:40:41 (permalink)
    0
    Thanks for your reply...! As you said it might be a problem with hardware. Right now i am not able go to my lab due to this COVID-19. after all these things got settled ,i will work on that and i will get back to you.
    #9
    Beau Schwabe
    Starting Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2019/09/23 21:16:53
    • Location: 0
    • Status: offline
    Re: High Frequency PWM using PIC16F15323 2020/04/06 08:44:31 (permalink)
    +1 (1)
    Hi, I write code purely in Assembly, so you might need to make a few adjustments.
    Take a look at OSCCON1 and OSCFRQ ... One gotcha with some micro's is when they sense a "Power up" versus a "Reset".  If you are connected to a ICSP during your testing, then the micro may sense that it is in "Reset" mode which defaults to a LOWER clock speed.  In software you can force it to another clock speed after a reset.  The code below will force it to the highest clock speed.
     

        banksel OSCCON1
        movlw b'00010000' ;HFINTOSC with 2x PLL (effectively running at 64MHz)
              ; X....... Reserved
              ; .XXX.... OSC Source
              ; ....XXXX Divider
        movwf OSCCON1
        
        banksel OSCFRQ
        movlw b'00000110' ;HFINTOSC = 32MHz
              ; XXXXX... Reserved
              ; .....XXX HFINTOSC Frequency Selection
        movwf OSCFRQ

     
     
     
    post edited by Beau Schwabe - 2020/04/06 09:14:47
    #10
    Ravikiran_H
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2020/03/20 05:14:34
    • Location: 0
    • Status: offline
    Re: High Frequency PWM using PIC16F15323 2020/04/07 01:32:19 (permalink)
    0
    Thank you..! i will try that also.
    #11
    Jump to:
    © 2020 APG vNext Commercial Version 4.5