PIC speed problems


Closed Thread
Results 1 to 40 of 40

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697

    Default PIC speed problems

    Hi, This is about the lighting circuit ive been making with LEDs. Im using PWM to fade the LEDs. With this being DC im just flashing them really fast (no zero crossing or anything like with 240V AC). The problem i have is when i send serial data to it it has to spend a few milliseconds processing the data. Thats causing the lights to flash. I dont think i will ever get rid of it completely but i want to minimize it as much as possible.

    Would someone be kind enough to tell me how long these things take please?
    Copy 1 byte from RCREG into a variable
    Copy 1 byte from a variable to another variable
    If statements with 1 condition (EG "if aByte=255 then")
    Passing a set value to a variable (EG "aWord=3000")
    Bit masking (EG "temp & %11111100")
    Bit shifting (EG "temp >> 2")
    SELECT CASE. Does this take longer for matches further down the list?
    Clearing serial buffer problems (cant remember which problem) RCSTA.4=0 / RCSTA.4=1

    I know i asked about 1 or 2 of those before but i cant remember which and i cant find the thread. If i know how long it takes for each thing then i can spread them out more evenly and add more pauses in when no data is arriving to balance things out a little.

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Which PIC are you using? If it has hardware PWM, then use that and it will eliminate the blinking completely.

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Its a PIC16F87. From what i can see it only has 2 PWM outputs. I need 4. Good idea though. I never thought of that. Maybe if there is another 18pin PIC with 4 PWM outputs then i can use it

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Its a PIC16F87. From what i can see it only has 2 PWM outputs. I need 4. Good idea though. I never thought of that. Maybe if there is another 18pin PIC with 4 PWM outputs then i can use it
    Or, you could look up Slow Speed software based PWM and get almost as many channels of PWM for messing with LEDs as your PIC can handle.
    I've been able to do 20 RGB LEDs (3 colors each of course) at 152.5Hz (way fast enough to prevent flickering), serial data input/output (using the PIC's hardware modules), key pad scanning, reading an eeprom, housekeeping chores, etc. all using a software PWM scheme based off Timer 0. Works like a champ, no flickering, etc.etc. That's with an 18F at 40Mhz. Use a 16F at 20Mhz, and you'll still be able to get 76.2Hz (again, fast enough to prevent flicker) and still be able to drive a load of software based PWM outputs on an 18pin PIC.

  5. #5
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Ok, ill have a look around for it. Im using a 20MHz oscillator already. The baud rate for the serial data is 115200. I would have thought that uses more processing power but i did have this working earlier. The problem seems to be with the code between the serial data arriving and the LEDs being turned on. Im still cutting as much out as possible but theres a limit to how small a program can be before it doesnt do everything you want. Ill probs strip my program back to basics when i test out that software PWM thing then build it up a few lines at a time.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    You're using an 'F87, I used an 'F628A. 15 I/O pins available for me, 2 used for 20Mhz crystal, 2 used for Serial I/O, PGM/MCLR tied as needed, 3 buttons and 6 LEDs (2 RGB), and one spare pin. I was able to do serial at 19,200 without a problem using the hardware module (datasheet says it's 1.7% high, but it worked). Used Timer0 kicking an overflow interrupt at 19.531khz, software PWM for each LED at 76.2Hz, 8 bit resolution. Could get a higher refresh rate at the expense of resolution. Once in a great while, I'd get a slight bit of one-time flicker if I was trying to receive serial data too fast or send it too fast, but that's completely up to the software driving it.
    I think that 'looping' PWM will end up kicking your butt in the long run, but that's just me.
    Time to learn how to use interrupts to your advantage!

Similar Threads

  1. Serial VB 2005 pic 16f877a problems
    By Snap in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 8th July 2013, 00:52
  2. Pic Vrs Atmel speed
    By shawn in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2008, 21:50
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. IC2 pic 18f452 program problems
    By MrSafe in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 20th September 2007, 18:55
  5. Help, problems first time with 18F452 PIC
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2005, 20:49

Members who have read this thread : 0

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