Tasks combined with non breaking delay

58 views
Skip to first unread message

dirk

unread,
Sep 19, 2012, 6:18:13 PM9/19/12
to jal...@googlegroups.com
Hello group,

I am trying to do a project with several tasks, but I am having trouble getting it going.
Can anyone tell me why the following code doesn't work?

-- JAL 2.0.4
include 18f2520
pragma target clock 20_000_000        -- oscillator frequency
-- Configuration memory settings (fuses)
pragma target OSC  HS             -- HS crystal or resonator
pragma target WDT  disabled        -- no watchdog
pragma target LVP  disabled        -- no Low Voltage Programming
--
pragma task 2
-- Enable delays without blocking
const timer0_isr_rate = 1000            -- 1 kHz isr rate
const DELAY_SLOTS = 1                   -- support 1 delays at the same time
include timer0_isr_interval
timer0_isr_init()                       -- init timer0 isr
--
enable_digital_io()                -- Make all pins digital I/O
--
PORTA_direction = OUTPUT
--
task Something() is
    forever loop
        --do something   
        suspend
    end loop
end task
--
start Something()
set_delay(0, 100)
forever loop                 
    if (check_delay(0)) then
         pin_a0 = ! pin_a0
         set_delay(0, 100)
    end if
    suspend
end loop

I expected the led on pin  A0 to blink every 10th of a second, in stead it blinks at a much slower rate (every minute).

Please help me out. 
Greetz, Dirk 

Joep Suijs

unread,
Sep 20, 2012, 2:43:46 AM9/20/12
to jal...@googlegroups.com
Hi Dirk,

Most of my apps have what you could consider 'tasks'. However, I use
non-blocking state machines instead of the jal TASK feature, because I
fail to see the added value of this feature since it only allows
'suspend' at level0 (there are other reasons too, similar to the
discussion if/when an RTOS is worth while).
But I am happy to learn, so please enlighten me if you think I am
missing something ;)

When reading the issue, the first questions that comes to mind are
- does blinking work as expected without tasks?
- is the issue in the isr (in other words: does it take more time to
decrease the counter) or in the task/main loop (does it take more time
to see the counter is zero)?
- is the issue also there when you don't start the second task?
I had a glance at your code and it looks okay and clean to me. You
might want to take a look at the asm file to see what code is produced
by the compiler to handle both tasks (and particual, the way it
suspends / switches).
I don't recall much on tasks at the yahoo jal group, but since this
group is much larger, you might get more info there.

And in case you can't convince me to give tasks a try, you might
consider creating your 'tasks' as small, non-blocking procedures and
call them from the main loop. The delay slot sample shows how to
control the calling frequency of different tasks.

Joep


2012/9/20 dirk <dj.b...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "jallib" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/jallib/-/d5RX2TFoiAgJ.
> To post to this group, send email to jal...@googlegroups.com.
> To unsubscribe from this group, send email to
> jallib+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/jallib?hl=en.

Rob Hamerling

unread,
Sep 20, 2012, 5:00:58 AM9/20/12
to jal...@googlegroups.com

Hi Dirk,

I cannot really help you with the task issue, I have no experience with
tasks under Jal. But I noticed a frequently made mistake!


On 20-09-12 00:18, dirk wrote:

> --
> PORTA_direction = OUTPUT
> --

'OUTPUT' is a bit constant. So in fact only pin_A0 is set to output
(which happens to be OK in this case, but is pure luck!)
If you want to set all pins of PortA to output then you should use:

PortA_direction = ALL_OUTPUT

Regards, Rob.

--
R. Hamerling, Netherlands --- http://www.robh.nl

dirk

unread,
Sep 20, 2012, 6:39:43 AM9/20/12
to jal...@googlegroups.com
Hi Rob,

Thanks for pointing this out. I will change this in my code.

Greetz,
Dirk

dirk

unread,
Sep 23, 2012, 4:57:20 PM9/23/12
to jal...@googlegroups.com
Thanks Joep for your advise. I have now stopped investigating the use of tasks for my project.
In the last days I reprogrammed my subroutines to delay state machines and three procedures are working nicely together now. I never programmed state machine procedures before, so this was a fine practice for me as well. Thanks again for pointing me in this direction.

Greetz, Dirk

Op donderdag 20 september 2012 08:43:47 UTC+2 schreef Joep het volgende:

Joep Suijs

unread,
Sep 26, 2012, 12:02:37 PM9/26/12
to jal...@googlegroups.com
You're welcome.

IMO the state machine is *the* most important concept for real time
embedded systems development.

Joep

2012/9/23 dirk <dj.b...@gmail.com>:
> https://groups.google.com/d/msg/jallib/-/5CRI11nsvfYJ.
Reply all
Reply to author
Forward
0 new messages