Multi-Threading


Closed Thread
Results 1 to 23 of 23

Thread: Multi-Threading

Hybrid View

  1. #1
    Ted's's Avatar
    Ted's Guest

    Default Multi-Threading

    Is a 16f628a + pbp capable of multithreading? Is it capable of letting a led flash while proceeding another task to symbolize that it is busy?

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

  5. #5
    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.

  6. #6
    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.

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