Multiple PWM and port C


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    Interestingly, I have the temp sensor (18B20) on port RA5. If I use RA4 and RA7 as the PWM pins the temperature reading goes heywire, displaying random temperatures like 163C but is often trying to over write the display. With RA4 and RA7 set as the pins for pWM, the clock on C3 and C4 runs fine....

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    OK, so then it's some kind of interference between the SPWM routines and the rest of the program, perhaps a read-modify-write issue, I don't know. But then you say that you had a version with both SPWM and I2C on the same port (different pins of course) which DID work so I don't know. Hopefully Darrel or someone else who's been using the routines in quesiton will jump in.

    Back to the hardware PWM.... Did you set the registers manually or did you use the HPWM command?
    If you set the registers manually then the number of bits of resolution you get depends on the frequency you select so a dutycycle value of 255 doesn't neccesarily mean 100% - it depends.
    If, on the other hand, you DID use the HPWM command then you should have got 100% with a duty of 255 - given you had told the compiler the correct operating frequency, ie DEFINE OSC xx.

    I still think you should concentrate on getting the CCP modules to do the PWM for you. Post the code for that and I'll take a look.

    /Henrik.

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    Well I just re-loaded the test code that uses port C for both clock and PWM pins and that appears to do the same thing, with 10:10 shown as the time. Mind you I've been cutting and pasting bits of code from one to the other to try and resolve this.

    When using CCP modules I simply used CCP1CON = %00000000 and CCP2CON = %00000000 to set the register and then used PBP HPWM command to drive the pins....

    I'll drop you a PM with the code....

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


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    Hi,
    Took a quick look at the code you PM'd me and found this:
    Code:
    'If light=1 then                         ' If the variable is 1 then output full PWM to lights
    '    hpwm 1,255,200        
    '    hpwm 2,255,200
    'endif
    'If light=0 then                       ' If the variable is low then set value to 0 an turn off the lights
    '    hpwm 1,0,200        
    '    hpwm 2,0,200    
    'endif
    If this is where you're trying to set 100% dutycycle but ends up with a "jumpy" signal not at 100% then the problem is most likely that you're trying a frequency (200Hz) far below the specified minimum. If you look at the manual you'll see that for a 18F device running at 20MHz the minimum frequency is 1221Hz.

    The only other place in the code where HPWM was used had a frequency of 5kHz so that should've worked - did it?

    /Henrik.

  5. #5
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    Took a quick look at the code you PM'd me and found this:
    Code:
    'If light=1 then                         ' If the variable is 1 then output full PWM to lights
    '    hpwm 1,255,200        
    '    hpwm 2,255,200
    'endif
    'If light=0 then                       ' If the variable is low then set value to 0 an turn off the lights
    '    hpwm 1,0,200        
    '    hpwm 2,0,200    
    'endif
    If this is where you're trying to set 100% dutycycle but ends up with a "jumpy" signal not at 100% then the problem is most likely that you're trying a frequency (200Hz) far below the specified minimum. If you look at the manual you'll see that for a 18F device running at 20MHz the minimum frequency is 1221Hz.

    The only other place in the code where HPWM was used had a frequency of 5kHz so that should've worked - did it?

    /Henrik.
    Hi,

    That section had been commented out from when I was using the hardware modules. It was intended as a manual over-ride so that I could turn the lights on or off via the push of a button. I never ran the module at high frequencies as the LED driver requires a PWM frequency of 100 hz - 1khz and at 1 Khz they resonated with a high pitched sound.

    The original code had
    Code:
    '*******************************************************************************
    'Send pulses to drivers
    
        hpwm 1,W_PWM,200        
        hpwm 2,B_PWM,200
        
    '*******************************************************************************
    Where W_PWM and B_PWM increased from 0 to 255 or decreased from 255 to 0 to fade the LEDs up and down
    Last edited by Scampy; - 11th December 2013 at 17:01.

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    I've just tried cutting and pasting the code into a new page and renamed it - complied and loaded and got the same results when using C1 and C2 as the PWM pins. If I comment out the include "Multi_SPWM.pbp" the program runs fine, but I obviously have no outputs from the two pins.

    So maybe you're right Henrik, in that there is some clash with the timing / or i2c bus ???

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    Hi,
    Since it seems to work when you're using SPWM on one port (PortB for example) while the I2C is on another (PortC) I don't think it's a timing thing.
    Since it does NOT seem to work when the SPWM is on the SAME port as the I2C I think it's some other sort of interference where the SPWM is messing with the I2C pins, possibly due to R-M-W but I don't know for sure.

    As for the hardware PWM....
    The original code had
    Code:
    '*******************************************************************************
    'Send pulses to drivers
    
        hpwm 1,W_PWM,200        
        hpwm 2,B_PWM,200
        
    '*******************************************************************************
    Well, then that IS the problem you're having - you're trying to run it at TO LOW frequency, which was the point I was trying to make.
    At 20MHz oscillator frequency there is no way to actually get 200Hz from the CCP module, the lowest possible frequency is 1221Hz.

    /Henrik.

  8. #8
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Multiple PWM and port C

    Changing ADCON0 to a value of 7 and changing the SW PWM pins to C1 and C2 made the clock to something, but it's still not running. The clock displayed 45:00 and then counted up in seconds (45:01, 45:02 etc) until it reach 14:10 and then displayed the 45:51. It remained displaying this "time", then changed to 45:52 a minute later, followed by 45:53 etc but there was no change in the case and the LEDs didn't light.

    Not sure if changing ADCON0 to 7 (all digital) had a bearing on things

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