Multi-Threading


Closed Thread
Results 1 to 23 of 23

Thread: Multi-Threading

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Interrupts are the ticket.

    This is pretty cool,
    http://www.picbasic.co.uk/forum/showthread.php?t=3251
    Last edited by mackrackit; - 9th August 2008 at 00:56.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Ted's's Avatar
    Ted's Guest


    Did you find this post helpful? Yes | No

    Default

    What is the connection to my question? How do you create a program that lets a led flash while proceeding with another task to symbolize that it is busy using your interrupt thingy?
    Last edited by Ted's; - 10th August 2008 at 16:44.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Well, the connection is... Multithreading is pretty much the same as an interrupt.
    This may help you understand it a bit.
    http://en.wikipedia.org/wiki/Thread_(computer_science)
    So if someting tries to start another "task" an interrupt is flagged. How you do this or what you do with it is up to you.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Read and understand

    Hi,

    If you look at the second post in this thread :

    http://www.picbasic.co.uk/forum/show...stant+interupt

    you will see a code snippet that ALMOST does what you want to do. It has a main loop where it is just performing a pause and then a timer is setup to toggle the led.

    This is very close to what you are asking for.. just enable the interupt before entering your task (so the led will start to flash) and when you exit your task disable it again.

    If you change the preloaded value (and prescaler if you have to) for the timer you can have different fast flashing led depending what task you are performing...


    This is not difficult because of the EXCELLENT code provided by DT.


    Code:
    LED1   VAR  PORTB.1
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    
    
    goto main
    
    my_task:
    T1CON = $31                ; Prescaler = 8, TMR1ON to desice how fast we will flash
    
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    ;do all the stuff you want to do here
    
    @ INT_DISABLE  TMR1_INT     ; DISABLE Timer 1 interrupts
    
    RETURN
    
    
    Main:
      GOSUB my_task 
      PAUSE 10
    GOTO Main
    
    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    This might ( I didn't compile and test it, and I am not sure if it is the right register for your PIC) work and should flash the LED while you are performing my_task only.. just remember if my_task is very fast you might come out of it before we flash since the LED is flashing once per sec or something now.

    also we will go back to my_task every 10 sek... but what you do in your main loop I leave to you to decide.

    /me
    Last edited by Jumper; - 10th August 2008 at 16:50.

  5. #5
    Ted's's Avatar
    Ted's Guest


    Did you find this post helpful? Yes | No

    Default

    This seems to be time critical, so if a pauseus is included the other task won't continue.

    What I actually want to do is this: (see picture)(strongly abbreviated)

    Down means LED is off, Up means LED is on. The x-axis represents time.

    So it is a LED light - fader.

    So time could be 100ms meaning the LED is being switched on successively in a repeating manner till it will have taken 50ms then the process is reversed amounting to a total of 100ms.

    Can you suggest a code for this?
    Attached Images Attached Images  
    Last edited by Ted's; - 10th August 2008 at 16:55.

  6. #6
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default hmm confused

    To start with by using DT instant interupts the interupt will be performed no matter what the PIC is up to for the moment.. The PIC will stop in it tracks, do the interupt, toggle the led, return and then comtinue off where it was before.

    First you wanted to flash a LED to show a busy task, now you want to fade a LED....

    Is that one led or 255 leds or fading while doing other stuff..... I think I speak for more people than myself when I say "hmmm confused"..

    What have you done previously, how much do you know about the PIC HW and what will your project do when it is done?

    Good luck and I will keep an eye on this thread to see if I can help later on

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jumper View Post
    I think I speak for more people than myself when I say "hmmm confused"..
    Me too, sounds like this is going a different direction.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Ted's's Avatar
    Ted's Guest


    Did you find this post helpful? Yes | No

    Default

    First of all you have good English. We are talking about one led fading in and out which is being repeated. Imagine a flashing led. Now imagine the led is on. Imagine it not being on instantly but having an increase in brightness. Then imagine it having a decrease in brightness. Increase and decrease amount to flashing time. It softens the led's appearance.
    Quote Originally Posted by Jumper View Post
    Is that one led or 255 leds or fading while doing other stuff..... I think I speak for more people than myself when I say "hmmm confused"..
    Last edited by Ted's; - 10th August 2008 at 21:08.

Similar Threads

  1. Multi Slow speed PWM and Instant Interrupts
    By DaveC3 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd November 2010, 12:50
  2. multi functions button press
    By malwww in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th May 2009, 00:12
  3. 16-48 pin Multi slow PWM
    By krohtech in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th March 2009, 03:28
  4. Multi diomencinal array
    By morphyn in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th February 2009, 21:19
  5. parallel port multi pic programmer?
    By SuB-ZeRo in forum Schematics
    Replies: 8
    Last Post: - 25th June 2005, 10:20

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