Interesting delay problem


Results 1 to 3 of 3

Threaded 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.

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