Shop OBEX P1 Docs P2 Docs Learn Events
Hello, I need to know if can I have multitasking with one SX28 ACDP microcontro — Parallax Forums

Hello, I need to know if can I have multitasking with one SX28 ACDP microcontro

markustermarkuster Posts: 184
edited 2007-06-20 19:43 in General Discussion
Hello,

·I need to know if can I have multitasking
with one SX28 AC/DP microcontroller.

Do you know information about that ?

Thanks, Mark

Comments

  • BeanBean Posts: 8,129
    edited 2007-06-19 02:05
    What type of multitasking ?
    What operations do you want to multitask ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • markustermarkuster Posts: 184
    edited 2007-06-19 02:28
    Thanks:

    I want to use the basic compiler to move
    two servos and a little piezo and a pair of
    light sensors.

    Do you know if SX are better for multitasking
    than Basic Stamps.

    Thanks, Mark
  • JonnyMacJonnyMac Posts: 8,943
    edited 2007-06-19 02:48
    I've attached a framework program that will show you one way to do it -- note that this is a simple program so the Interrupt Service Routine is coded in SX/B.
  • markustermarkuster Posts: 184
    edited 2007-06-19 18:43
    Thanks,


    Do you know if can I "join" two or more SX28
    in order to have something like the propeller,
    something with real multitasking?


    thanks, Mark
  • BeanBean Posts: 8,129
    edited 2007-06-19 18:49
    You could but you would be better off just using a propeller.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • markustermarkuster Posts: 184
    edited 2007-06-20 01:51
    Thanks Bean:


    But the problem I have is that the SX chips have
    the Basic compiler (very similar to Basic Stamps)
    and the Propeller doesn't have basic compiller . Propeller
    uses a Spin lenguaje and it is different to Basic.

    Do you know if there are or if Parallax will develop
    somethig like to Basic for the Propeller ?

    Thanks, Mark
  • PJMontyPJMonty Posts: 983
    edited 2007-06-20 01:57
    Mark,

    Why do you want "real" multitasking. If "standard" multitasking (simulating multiple processors through some form of time sharing) accomplishes your goal, AND you already have the SX chips and IDE, then just use it. There are millions of computers out there multitasking away (almost every PC and Mac for example) and accomplishing lots of useful goals. If you don't know how to multitask with a single processor, then it sounds like there are still things for you to learn about the SX. I would stick with what you know until it no longer can do what you want.

    Thanks,
    PeterM
  • BeanBean Posts: 8,129
    edited 2007-06-20 12:20
    markuster said...
    Thanks:

    I want to use the basic compiler to move
    two servos and a little piezo and a pair of
    light sensors.

    Do you know if SX are better for multitasking
    than Basic Stamps.

    Thanks, Mark
    Mark,
    · I don't think you would need multitasking to to what you want.
    · Just have your main loop do each thing one after the other.
    · The servos should only be updated every 20mSec or so anyway.

    Bean.

    ···

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2007-06-20 14:18
    The 2004/5 SX Design Contest has a multitasking system as one of the honorable mentions.· Of course, this is assembly language - not SXB.· But any really good multitasking will probably be in assembly language in order to be compact and fast.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Everything in the world is purchased by labour; and our passions are the only causes of labor." -- David·Hume (1711-76)········
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • ZootZoot Posts: 2,227
    edited 2007-06-20 19:43
    Mark, I concur with Bean -- if your initial goal is to run the piezo, a few light sensors, and some servos, keep it simple until you need it more complex.

    You can develop a program that will "appear" to run everything at the same time ("multitask") since the SX is very fast, and 20ms between servo pulses is a lot of time to get other things done.

    Here is a pseudo-code outline that may help:

    
    Beginning:
    
        ServoTime = 0?   'if you countdown your servo timer to 0, send a pulse
              Yes --> send servo pulse(s) to servo pins
                    --> reset ServoTime to equiv. of 20ms to countdown to next pulse
               No --> ServoTime = ServoTime - 1
         LightTime = 0?  'similar to above, but it's how long between light sensor measurements...maybe 10x per second (100ms)?
               Yes --> get light values into LightValL, LightValR, etc..
                    --> reset LightTime to evuiv. of 100ms
                No --> LightTime = LightTime - 1
    
          PiezoTime = 0? 'ditto -- how often should script check for something to send to piezo -- this could be trickier without an ISR
                                 'as you might need to break your sounds into small chunks that fit between 20ms servo pulses
                  Yes --> make a sound, reset PiezoTime
                  No --> PiezoTime = PiezoTime - 1
    
     Middle:
           
            LightL > 200   'is light on the left? turn that way
                Yes --> ServoL = 140, ServoR = 160
            LightR > 200   'is light on the right? turn that way?
                 Etc.            'turn right
    
    
     End:
          GOTO Beginning
    
    
    



    So basically your SX rips through the loop at blazing speed, but what actually happens during each loop depends on the state of the timer(s) -- the actual "send to servo" code will only run when 20ms has elapsed, etc. The above is over-simplified, but hopefully it gives the general idea of how you might approach the project. My own style is usually to use just a few counters, updated regularly, and then divide them for my different "tasks", but the individual timers above are easier to read.

    JonnyMac's ISR routines, and PJV's multi-tasking threads give much tighter timing control and lets you run code virtually in the "background", which could be helpful for your sound work. But understanding the basics of something like the above would help. I've done similar setups on Stamps as well, though they are much slower overall.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
Sign In or Register to comment.