I understand the theory of this, but I wasn't sure what constants to
put for the 48Mhz 18F4550 rather than the 16F877
the 16F877 sample uses
OPTION_REG_T0CS = 0
OPTION_REG_PSA = 1
in the main program
putting these for 18F4550 seems to work
T0CON_T0CS =0 -- TMR0 on internal clock
T0CON_PSA = 1 -- prescaler
I have not rigorously tested this, but it *seems* to work
I'm not worried about any usDelay accuracy anyplace.
I had wanted to have my RadioWidget, ClockWidget, RDSWidget and
UserInput as Tasks.
**BUT**
Two issues.
1) I can't figure how to compile. The main loop had a suspend and 4
tasks started before the forever in main program. Jaledit compiler
Option set to 5 tasks
The Compiler complained I needed >= 2 tasks. Perhaps the option is not
passed from Jaledit?
2) Even making a procedure called in a Task as "inline" I can't put
"suspend" in middle of a Procedure. Between sending a 5 byte command
(via serial) and starting to receive 1 to 5 bytes back (depending on
command) is up to 350ms! This is REALLY good place to suspend. The
alternative is to split all the CAT_commands that expect data back
into a Command Part and Response Part and call those separately in
main task loop with a suspend inbetween.
Allowing a Suspend inside a Procedure/Function called in a Task would
make it REALLY useful. If there are zero tasks in the program (i.e. NO
calls to Start myTask anywhere) then the compiler could simply delete
the suspend tokens?
I presume the limitation is stack on the low end PICs? (for which
Tasks are fairly useless anyway).
BTW why is "inline" a Pragma straight after "is" rather than a keyword
between procedure and the procedure name (like volatile goes between
var and byte etc)?
Also
Is Block .... end Block needed ever anywhere other than in "case"
statements?
-- Timer to Poll
-- Radio Control/Status, RDS decoder data, User Input
-- and update a Real Time Clock
-- The RTC always increments a Semaphore by 1 if it's time to do a
task
-- The Task always decrements the Semaphore by 1 when it has
completed.
var byte CheckTime = 0 -- semaphore
var byte CheckRadio = 0 -- semaphore
var byte CheckUser = 0 -- semaphore
var byte CheckRDS = 0 -- semaphore
var volatile byte seconds -- updated by ISR
const POLL_INTERVAL = 1368 -- 350ms
const TICK_INIT = 12
const USER_INIT = 100
var volatile word userCount = USER_INIT -- debounce keys
var volatile byte ticks = TICK_INIT
var volatile word poll_count = POLL_INTERVAL -1
const RTC_LOW = 3096
const RTC_HIGH = 3097
var volatile word rtc_count = RTC_LOW -- should be 3906.25
var byte rtc_error = 0
-- every 21.333 us at 48MHz x 3 = 64us
-- x12 = 256 us = RDS oversample
-- radio poll is 350ms 1368 x 256 us = 350.208 ms
procedure RTC() is
pragma interrupt
INTCON_TMR0IF = off -- clear the timer 0 interrupt flag
ticks = ticks -1 -- 256us counter
if (ticks < 1) then
ticks = TICK_INIT
CheckRDS = CheckRDS +1
poll_count = poll_count -1
if (poll_count<1) then
poll_count = POLL_INTERVAL
CheckRadio = CheckRadio +1
end if
userCount = userCount -1
if userCount < 1 then
userCount = USER_INIT
checkUser = CheckUser +1
end if
rtc_count = rtc_count -1
if rtc_count < 1 then
rtc_error = rtc_error + 1
if rtc_error == 4 then
rtc_error = 0
rtc_count = RTC_HIGH
else
rtc_count = RTC_LOW
end if
seconds = seconds +1
checkTime = CheckTime +1
end if
end if
end procedure -- end of ISR
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.