Interesting delay problem


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Sep 2008
    Posts
    2

    Cool Interesting delay problem

    i'm writing a code for control three leds from serial port. so i started with only one led at first.

    here is the codes :

    @ DEVICE PIC16F628A
    @ DEVICE PIC16F628A, WDT_OFF
    @ DEVICE pic16F628A, PWRT_ON
    @ DEVICE PIC16F628A, PROTECT_OFF
    @ DEVICE PIC16F628A, MCLR_OFF
    @ DEVICE PIC16F628A, BOD_OFF
    @ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT

    OPTION_REG = %10000000
    INTCON = %11000000
    PIE1 = %00100000
    TRISA=%00000000

    ON INTERRUPT GoTO kestirici
    CMCON=7

    define HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    define HSER_BAUD 4800

    led var byte[3]
    par var byte[3]

    par[0] = 128

    basla

    for led[0] = 0 to 255
    if led[0] < par[0] then
    high porta.0
    else
    low porta.0
    endif
    next

    goto basla

    disable
    kestirici:
    HSERIN [wait("t"),dec2 par[0]]
    Resume
    enable

    When i started this project.I was using pauesus to create duty cycles.But that was making a phase difference problem.So i searched,searched... for another methods to drive leds. Then i found timer interrupt.That was using timer for delays so there wasnt any phase difference problem. So i decided to use timer interrupt.

    But there was a problem again When i was trying to pwm one led with timer interrupt, that was fine. i got about 2000hertz. But if i try to pwm three leds. The frequency falls down about 60 hertz. (and i'm not even using hserin for all this codes yet).

    Whatever. 60 Hertz is not bad. But how was i'm going to use hserin with that codes? i tried to insert the hserin command to main loop. Didn't worked.Frequency falls down.Tried with timeout 1ms and 0ms. Frequency falls down again.

    After that, i decided to write timer interrupt codes to main loop and change the timer interrupt with serial interrupt.

    So here is my codes i get about 100hertz right now with one led. WHY? That should be about 2000 hertz like in the timer interrupt. Is that about if-statements? if i use less if statement, frequency increases.

    It is just one led. When i make it three. Frequency is about 30hz. That sucks.

    If you have another idea for control three leds(brightness) from serial port with about 100hz. I'm ready for do it. I'm tired. Trying to do this thing for 2 weeks.
    Last edited by Kreston; - 1st September 2008 at 13:32.

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    Dont be disheartened. It sure looks like you have the general idea to make it work. Now, what you can try to do is to take interrupts on Receive and Timer.

    In the Timer ISR, you can take care of the LEDs. In the Receive ISR, you grab the serial port character and either buffer it for the mainline code to see it (circular buffer) or signal it to the mainline if the data rate is very slow. This will help you decide on the Led states.

    You will definitely get better results with this method. If possible, try to keep the ISR code as short as possible and if you can do it, use assember in there. You got to try; may seem difficult at first, but once done, you'll wonder why you didnt do it before.

  3. #3
    Join Date
    Sep 2008
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    Thanks for quick answer. But how can use timer interrupt and serial interrupt together? Can you write a short sample code for that?
    and what do you think about huge delaying when three leds is being driven by the timer interrupt or main loop. As i said, its 2000Hz with one led.But 60hz with three leds. That's too much i guess.

    i have more questions I'm going to send one byte for each led, 30 times in a second.
    do you think baud rate is ok for this?

    one more i don't know so much about buffer. Can you explain it?

Similar Threads

  1. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Delay problem
    By lloyd778 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 26th October 2006, 06:42
  4. Memory Space of the PIC16F84...
    By Tear in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st July 2005, 19:55
  5. Problem with saving to EEPROM...
    By Tear in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st July 2005, 00:10

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