P-RTOS Real Time Operating System for PDS


Yesterday 22:13
Forum: Proton Plus Compiler v3
Starter: gdesantis
Views: 0
Replies: 0
Yesterday 18:35
Forum: The Lounge
Starter: Les
Views: 0
Replies: 11
+ Reply to Thread
Results 1 to 6 of 6

Thread: P-RTOS Real Time Operating System for PDS2509 days old

  1. #1
    Prolific Poster johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,060
    Thumbs Up
    Received: 87
    Given: 1
    Total Downloaded
    1.48 GB

    0 Not allowed!

    Default P-RTOS Real Time Operating System for PDS

    Downloads: P_RTOS all files download


    P-RTOS is a real time operating system provides a programming environment which allows routines to appear to run concurrently with each other. Such multitasking can make better use of the processor's resources when compared with the more conventional in line programming.

    Consider DelayMS to adjust the timing of an operation; with a real time operating system this need not be wasted CPU time as the processor can be released to do other tasks. P-RTOS uses a co-operative scheduler to effect multitasking. This means that, outside interrupts, your application must specifically Yield back to the operating system rather than the OS determining when to resume control.

    P-RTOS has been designed and written in Proton PICŪ Basic and provides real time services which can be used directly by your application. The OS takes the form of include files which you reference in your main program to use these services.

    A new approach to programming

    Programming in a P-RTOS environment requires your design to be more event driven with functions broken down into a set of tasks triggered by events. An event can be anything from a timer completing to a character appearing on a serial port.

    The links at the top of this article will take you to downloads of the P-RTOS manual, the source code and a demonstration program.

    A Real Life Example

    Part of the demo program includes a function to drive 4 R/C type servos and is a good real life example of the sort of techniques you will need to use.

    For the purposes of the demo, P-RTOS has been configured to use Timer1 as a basic 10 mSec timing source, referred to as an OSTick. This is the minimum period to which P-RTOS can resolve time. You could reduce this period further but given the same processor clock rate the shorter the tick period the greater the overhead P-RTOS will incur.

    For those unfamiliar with R/C servo operation the position of the servo is determined by the width of the pulse on its input which typically varies between 1mS and 2mS long, 0 to FSD. This must be repeated at a repetition rate of 50Hz or every 20mS to hold the servos in that position. In this example P-RTOS can only resolve down to 10mS so we need another way to generate the individual server pulses. For this we use Timer3. With the background set, let us look at a code extract for the servo driver and explain how it all works.

    There are 3 routines involved in this function; ServoDrv, ServoTmr and ServoISR and they co-operate with each other through the operating system.

    Code:
    ServoTmr: 
       OSStartTask T_ServoDrv                   ' Start the Servo driver.     
    Return
    The ServoTmr starts everything off. It is triggered by a cyclic timer, an OS resource which calls the routine at a set rate. In this example the OS calls the ServoTmr routine every 20mS or 2 OS Ticks. This gives us our basic update rate for the servos. The ServoTmr routine simply starts the Task ServoDrv and returns to the OS. The OS runs the ServoDrv task immediately there are no higher priority tasks waiting to run.

    The desired position of each of the 4 servos is held in a word array (ServoPositions). The 4 servo outputs are allocated to bits 0 to 3 of PortB. The ServoDrv Task sets up a mask to the first Servo, gets the first servo position, loads and starts Timer3, sets the port bit high, and Yields back to the OS (OS_WaitBinSem) to wait for the Timer3 to complete. See the first part of the ServoDrv below.

    Code:
    ServoDrv:
    Repeat
      SetMsk = 00001                              ' set mask initial value
      ClrMsk = ~ SetMsk                           ' set Clear mask initial value
      idx = 0                                     ' and index to first servo position
      Repeat
    Tw = ServoPositions[idx]                   ' Get Servo position
    WriteTimer3 Tw                             ' Set Servo pulse width
        StartTimer3                                ' Start Pulse Timer
        PORTB = PORTB | SetMsk                     ' Write to the port to set pulse high
        OS_WaitBinSem E_ServoDrv,1                 ' Wait on server pulse timeout
    ....
    The ServoISR is triggered by the interrupt generated by Timer3 when it completes. ServoISR stops Timer3, sets the port bit back to 0 and Signals an Event (OSQueue_Event) to the OS.

    Code:
    ServoISR:
      If PIR2.1 = 0 Then GoTo OSUSER_ISR_RTN      ' if Timer3 Interrupt Flag not set skip
      CloseTimer3                                 ' it's this ISR's interrupt so stop timer
      PORTB = PORTB & ClrMsk                      ' clear pulse to low
      OSQueue_Event E_ServoDrv | OSBINSEMEVNT     ' queue the event (Signal timeout for servo)
      Clear PIR2.1   
    GoTo OSUSER_ISR_RTN                           ' return to Main interrupt handler
    The ServoDrv Task has been waiting this Event and resumes from where it left off, incrementing on to the next servo. It continues in this sequence until all the servos have been serviced when ServoDrv stops and returns to the OS. See whole ServoDrv task below:

    Code:
    ServoDrv:   
    Repeat
      SetMsk = 00001                              ' set mask initial value
      ClrMsk = ~ SetMsk                           ' set Clear mask initial value
    idx = 0                                     ' and index to first servo position
    Repeat
        Tw = ServoPositions[idx]                  ' Get Servo position
        WriteTimer3 Tw                            ' Set Servo pulse width
        StartTimer3                               ' Start Pulse Timer
        PORTB = PORTB | SetMsk                    ' Write to the port to set pulse high
        OS_WaitBinSem E_ServoDrv,1                ' Wait on server pulse timeout
        If OSTimedOut = True Then SvError
        SetMsk = SetMsk <<1                       ' Update Set Bit Mask
        ClrMsk = ~ SetMsk                         ' Update Clear Bit mask
        Inc idx                                   ' on to next servo
      Until idx > 3                               ' until all servos serviced
    SvError:
      OS_Stop                                     ' stop and wait to be re triggered.
    Forever
    This whole sequence is restarted when ServoTmr runs next.

    This should give you a flavour of what you can do with P-RTOS. There is an important difference between Cyclic Timers and Tasks. Cyclic Timers call standard routines which must end with a Return. Tasks on the other hand never return but simply loop forever. To return to the OS from a task you must call one of the OS's yield services. In P-RTOS all yielding services start with OS_, and can only be called from a Task.


    The demo program contains much more, including a function to set the servo positions from a terminal so you can see the pulse widths increasing and decreasing. Also included are demonstrations of each of the major services provided by the OS. You can run this program in ISIS using the DSN file provided.
    Last edited by joesaliba; 4th February 2016 at 18:31.
    JohnB

  2. #2
    Junior Member andy wong's Avatar
    Join Date
    Mar 2005
    Posts
    15
    Thumbs Up
    Received: 1
    Given: 0
    Total Downloaded
    579.93 MB

    0 Not allowed!

    Default Re: P-RTOS Real Time Operating System for PDS

    I was not able to download with my forum ID and password!

    Andy

  3. #3
    Prolific Poster johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,060
    Thumbs Up
    Received: 87
    Given: 1
    Total Downloaded
    1.48 GB

    0 Not allowed!

    Default Re: P-RTOS Real Time Operating System for PDS

    Its a link to files on the WIKI so you need to user the WIKI login.
    Read what it says in the logion dialog

    A user name and password are being requested by http://click-server.com.
    The site says: "user: Protonuser Password: forumfiles"
    Then do what it says
    JohnB

  4. #4
    Prolific Poster pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    2,927
    Thumbs Up
    Received: 32
    Given: 31
    Total Downloaded
    926.61 MB

    0 Not allowed!

    Default Re: P-RTOS Real Time Operating System for PDS

    Would your RTOS be useful for commutating a brushless motor John?

  5. #5
    Prolific Poster johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,060
    Thumbs Up
    Received: 87
    Given: 1
    Total Downloaded
    1.48 GB

    0 Not allowed!

    Default Re: P-RTOS Real Time Operating System for PDS

    I suspect the overhead would be too high - I am assuming you are trying to get timings down to microseconds but it all depends on what you are trying to do.

    Currently I use P-RTOS with a 10mSec tick which means I can time-slice down to 10mSec. You could probably take it to down to 1mSec quite happily but I suspect for a brushless motor drive you would want to work at smaller time increments. I get round this in my P-RTOS demo with RC servos by using a timer to determine the pulse length for each servo and the OS Tick for the refresh.

    The point about a RTOS is to enable you to manage many concurrent tasks. In your case, it might be valid if you are wanting to handle a number of other events while maintaining control over the motor but if its solely for driving the motor then I think you would find it easier to do it in a tight loop.
    JohnB

  6. #6
    Prolific Poster pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    2,927
    Thumbs Up
    Received: 32
    Given: 31
    Total Downloaded
    926.61 MB

    0 Not allowed!

    Default Re: P-RTOS Real Time Operating System for PDS

  7. Ah ok. Thanks John.
    Hopefully my work load will calm down in the next month or so. I would like to spend some time playing with your RTOS

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 0
    Last Post: 4th March 2012, 18:14
  2. A Real Time Operating System for Proton.
    By johngb in forum WIKI Discussion
    Replies: 10
    Last Post: 22nd January 2012, 11:13
  3. real time clocks
    By ADLIN SYSTEMS in forum The Lounge
    Replies: 4
    Last Post: 7th June 2010, 19:22
  4. Real Time Clock
    By belsenthegreat in forum The Lounge
    Replies: 5
    Last Post: 27th February 2007, 23:14
  5. Real time charts/graphs
    By david in forum The Lounge
    Replies: 1
    Last Post: 31st December 2004, 02:23

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts