Multiple PWM and port C


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    Hi,
    The reason it runs slow is due to the interrupt driven PWM routines. You have a PWM frequency of 200Hz and a resolution of 256 steps, this results in an interrupt frequency of 51200Hz.
    According to Darrels page (if I'm on the right one) each "PWM-channel" needs 20 instructions - in your case 51200 * 20 * 2 = 2,048,000 instructions per second, just for running the 2 PWM channels. At 20MHz there's 5,000,000 instructions per second to play with which means that 40% of the processors time is spent running the PWM.

    You tell PBP that you're running at 20MHz but then the assembly interrupts silently eats away 40%.

    In this case each and every Hz you decrease the PWM frequency will give more time to the actual PBP program, if 100Hz is "all" you need then don't try running it at 200Hz. But again, it doesn't seem to be the timing per se that makes it NOT work since it using different ports for the PWM and I2C works.

    /Henrik.

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    Thanks for the explanation...

    I think I'll go back to using port D for the outputs and revert back to the mulit_swpm file. Not ideal, as I'll have to modify the PCB, but at least it works without the delays or screwing up the clock etc. If I get chance I'll try this on the old 16F877A chip rather than an 18F to see if this issue is chip related...

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    I've recorded the wave form when using the hardware PWM modules on the chip to explain the issue I'm getting.



    If you compare this to using the multi_swpm file and port D you notice there are loads of spikes in the HWPM signal and some harmonics ? - the amplitude is also a lot less (I had to increase the volume for the HWPM to get a similar trace)


  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    As I've said a couple of times now:
    You can not run the hardware PWM at a frequency below 1221Hz - it's not a bug in PBP and not a hardware issue with the PIC or the circuit, it's just the way it is.

    The reason is because TMR2, which is used for the PWM timebase is 8 bits wide and has a prescaler with a maximum ratio of 1:16. At 20MHz the timer ticks at 5MHz, so 5,000,000/256/16=1220.7Hz. If you try anything lower than that it will not work properly and I'm pretty sure that's what you're seeing when trying to run it at 200Hz.

    To prove or disprove, try it again at 1500Hz and see if the waveform looks better. I understand that it won't work in your particular application due to the LED drivers but it'll show that actual problem is that you're trying to run the PWM at a frequency (200Hz) which the module is incapable of producing.

    /Henrik.

Similar Threads

  1. Multiple PWM pins
    By Scampy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th November 2013, 19:23
  2. Darrel's Multiple Software PWM
    By passion1 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 15th October 2013, 15:21
  3. Drive multiple LED with one PWM
    By microuser in forum General
    Replies: 3
    Last Post: - 27th September 2007, 13:26
  4. Multiple Pics to One serial port
    By Rleonard in forum Serial
    Replies: 1
    Last Post: - 18th January 2007, 18:30
  5. Multiple IR LEDs from 1 port using transistor
    By belpe123 in forum General
    Replies: 3
    Last Post: - 20th May 2005, 22:07

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