PIC speed problems


Closed Thread
Results 1 to 40 of 40

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    I see your point. I will be adding some extra stuff to the main loop but the other stuff will only get executed if the current bit doesnt.

    It just seems like your way does a lot of unnecessary stuff. I can give it a go but it looks like a lot of processing that doesnt need to be done. Having said that, you know what your talking about and im new to this. Plus you say your code actually works and mine still doesnt

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    It just seems like your way does a lot of unnecessary stuff. I can give it a go but it looks like a lot of processing that doesnt need to be done. Having said that, you know what your talking about and im new to this. Plus you say your code actually works and mine still doesnt
    It really doesn't do a lot of extra/unnecessary anything. All it does (or rather would do) is, the interrupt's would handle the PWM'ing on the LEDs for you (you update them in the main loop as required) and would handle putting any serial data received into a buffer (you pull the buffer in the main loop to update the LEDs brightness levels in the main loop as required).
    Really very simple...That file that I attached earlier has a whole LOAD of code in it for handling various modes for this, that and the other thing (sleep mode, flashing, fading, color 'phasing', etc.etc.)...a LOT of stuff you wouldn't even come close to needing for your setup.

    I modified that file I was talking about...4 channels (RGBW)...
    Change it up a bit to fit your PIC and hardware and try it out. No serial support, but it'll show you how the main loop can work PWM'ing with interrupts on the LEDs.
    The LEDs MUST be on portA for this exact code to work right. If you split up the LEDs between different ports, they may flash a bit funny...
    Attached Files Attached Files
    Last edited by skimask; - 7th October 2008 at 18:50.

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


    Did you find this post helpful? Yes | No

    Default

    Ok, thanx. Im home now and im having a little trouble getting the timer interrupt working so ill read that file and see if i can get it working

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Ok, thanx. Im home now and im having a little trouble getting the timer interrupt working so ill read that file and see if i can get it working
    You're still using a 16F87 right?
    How about your hardware? How's that all hooked up? LEDs? Serial input? Anything else hooked up?
    Get me that info...lemme cook on it for a bit...

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


    Did you find this post helpful? Yes | No

    Default

    Ive managed to sort it out. I almost came back with the info but i wanted to try and fix it myself. Ok, it took about 3 hours but i got there in the end.

    Ive tried changing the pre-scaler too. i thought maybe a 2:1 ratio would free up a little extra processing time. Well, in theory it should because the PWM side of things is only using half the processing power. Unfortunately it didnt affect it in the way i wanted at all. All it did was make the lights flicker a bit because they were flashing too slow so i disabled the pre-scaler.

    Now then, theres a sort of random problem. I currently have VB 6 in a loop sending 513 bytes of data. The PIC is processing the data and setting the PWM values. Well, its setting the same values over and over but its still processing and holding different colors in different PWM positions. Its actually working perfect

    Now the random problem. If i have a scroll bar that sends the data in the onchange/onscroll then the LEDs flicker quite bad. I really dont understand how that could happen. The circuit is obv working and im sending 513 bytes of data so the baud rate isnt so high that its affecting it. The only thing i can think of is the gap between the last byte and the first byte of the next set of data is less than the gap between the bytes in 1 packet. That seems impossible though and if it did that then i wouldnt have thought you would notice.

    Do you have any ideas? I just cant get my head around this one

    Edit: Ive added some code to time the serial data going out of VB. Aparently it sends a full 513 bytes every 35-46 milliseconds and thats when it works fine
    Last edited by The Master; - 7th October 2008 at 22:09.

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


    Did you find this post helpful? Yes | No

    Default

    I have a theory! I just added some code to the loop (the working part) to change the value of the red LEDs and its started flickering a little. I belive the problem is in the way ive done the PWM.

    The PWM counter starts at 255. Everytime TMR0 overflows it decrements that value then compares it with the value of each LED. If they match then it turns the LED on. When it gets to 0 it resets back to 255 and turns off any LEDs whos value is less than 255. I think that by changing the value sometimes the PWM counter "misses" the LEDs value so it never turns on until the PWM counter resets to 255 and comes around to the new value.

    When testing DT's code i think he does it the oposite way. Turn the LEDs on and count up then turn them off when the value matches. When testing that code the LEDs seemed to flash brightly rather than turn off for half a second.

    Im gonna try and fix that problem but again i wouldnt have thought missing 1 PWM cycle would affect the LEDs that bad

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


    Did you find this post helpful? Yes | No

    Default

    Wow, that was quick. I fixed that little problem and all the flickering seems to have gone away! Ive just been moving those scrollbars as fast as possible and they wont flicker at all now.

    Although i have learned quite a lot from this thread and finally been able to link a lot of that stuff in the datasheet (the registers) to something usefull, i get the feeling that i could have solved this in the origional code simply by replacing "=" with "=>" 4 times.

    Oh well, its not a problem... just a learning oportunity

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