Subject: Something I just learned about real time and BASIC .
From: Rotary Engine
Date: 6/6/2010, 2:56 PM
To: AAA Put this in the To box

There is real time and then there is REAL TIME.
Controlling the fuel injection and the ignition
timing on a multi rotor or  multi cylinder engine requires
absolute control down to the nearest micro second.
One millionth of a second. You must know exactly
how long it takes to complete any instruction.


One of the strengths of ZBASIC and other BASICs is; it can
deal simply with floating point numbers (and other types
of numbers) in the range  of +/- 2 million.

Unfortunately an 8 bit computer needs four or more
memory locations to store numbers that large. Maybe
more. The computer must read those memory locations
one by one in the proper sequence.

If the computer receives a hardware interrupt
and is forced to go out and immediately do something else
while it is the process of reading the memory locations the
number could be garbled.

Now this could be just ZBasic. It could be a function
of the compiler. I am not sure but BASIC's running on
powerful computers with over 80 I/O pins are few and far
between so I am sticking with the Atmel and ZBasic.

So I decided to do the time critical stuff in hardware
such as trigger the ignition and determine the RPM Â and
not worry about it.

Paul Lamar


Paul,
This is what a floating point processor / coprocessor does
for you; makes 'float' operations atomic. What you're seeing
is the compiler simulating floating point ops using integer
registers. You should try to stick with 'int' as much as possible.

I've been working on hanging the rad, oil cooler, relocated
oil filter, etc. Also been working on the exhaust manifold.
I purchased the RX8 exhaust flange from Mazdatrix, and was
disappointed to discover machining was required to correct
the alignment with the exhaust ports. I purchased some 321
0.060 stainless elbows and am experimenting with routing
configurations.

--Kenny A.

The Atmel does not have a math co processor.

The term "atomic" is interesting. It confuses the
heck out of me :)

"In ancient philosophy, an atom was the ultimate unit
of matter on which more complex views of material reality
were based. In computer programming, atomic describes a
unitary action or object that is essentially indivisible,
unchangeable, whole, and irreducible."

What does it mean in Dick and Jane language? :)

Me too on that RX8 exhaust flange. Lots of die grinding
required.

Paul Lamar


Anything that is considered ATOMIC happens without interruption.
Some instructions are complex and take many clock cycles. If the
instruction is atomic then it will not be interrupted before it is
finished.
--
Blake C. Lewis

Thanks Blake that is very clear. Now I understand.
Let me paraphrase from a single board assembly language
point of view when speaking about a high level language.

"If the instruction is atomic then it [MUST] not be interrupted
before it is finished."

That in a nut shell is the major problem with real time
hardware interrupts and high level languages.

In the real hardware world interrupts can come in at any
time such as the CAS signal and they must be dealt in the shortest
possible time.

They are handled by the asm programmer
by stopping the so called atomic HL instruction, saving all the
variables having to do with that HL instruction on a device called
a first in last out stack (I'll explain later) and executing what
needs to be done right now for that hardware interrupt like
firing the plugs lickity split.

It then restores all the variables and  goes back to the point
in time  where the "atomic" HL instruction was executing and
allows it to start executing again.  I suspect the guy that wrote
ZBasic did not fully understand this or choose to disable
hard ware interrupts while certain HL atomic routines were executing.
The "certain" HL routines involved had to do with what he felt
were time critical tasks. On the other hand using assemble language
the programmer must deal with the time it takes to execute any and
all instructions or  routines in excruciating detail. Nothing is
really considered atomic.

As you can see this is a real can of worms.

What I choose to do was not use ZBasic for time critical hardware
interrupts like firing the plugs on time and determining
the RPM. I am designing a few hardware modules that will
interface with ZBasic and use what ZBasic is good at. Namely
making decisions and doing the math. The Atmel ZBasic 1280
pc board is ideal for this approach as it has over 80
I/O bits to connect to the outside world. I will
use 16 of those bits just for determining the RPM.

I also changed the the whole philosophy of the
traditional EFI system by choosing not to inject
fuel at specific times. Once this choice is made
this frees the computer for having to do everything
in 4 milliseconds at 7500 RPM. Our engines runs so fast
most of the time it probably does not care and can not
tell  when the fuel is injected. Most aircraft fuel
injection systems work this way.

You cannot say this about a car engine idling or
going down the freeway at under 2000 RPM. The
computer has a lot more time to do everything
in a given time period.

The big pay off is the pilot will receive a wealth
of engine information on a large screen in what
he perceives as real time. Faster than his eyes can
perceive the changes. It will be slowed down
so he can read it. All engine information such as
EGT, injector pulse width, fuel burn rate, total
fuel burned,  manifold pressure, RPM, engine water
temperature, oil temperature  and etc., etc., is also
recorded every second. A black box for GA. That capability
is a built in feature of ZBasic and most Basics for
that matter. A $200 net book does that job. Solid state
40 gig flash memory if you choose an EeePC.  In effect
we are using multiple processors.

That was also a feature of my moving map program, written
in QB, back in 1990 running on a DOS PC. No it won't
run under Windows :) I can send you the source code
however. The data was stored on a floppy drive.

You implement this EFI  and a recording EFIS is thrown in
for free. The same EFI hardware does both things.

Paul Lamar


Paul,
We're getting into the weeds here, but I'm compelled to
make one clarification. The statement:

"If the instruction is atomic then it [MUST] not be interrupted
before it is finished."

misinterprets 'atomic'. Atomic operations are protected
by hardware and cannot be interrupted regardless of
programming in a high/low level language. It's not optional.
The interrupt controller will wait on it.

Real-time software is generally categorized as 'soft' or 'hard'
(deterministic) real-time. 'Soft' real-time usually means it's
non-deterministic, can cope with disorderly interrupts,
multi-tasking, etc., and if it doesn't work you just throw
faster hardware at it. These can be programmed in any language
(Java, VB, etc), the overhead of the app/run-time driving the
required processor performance.

'Hard' real-time means the system requires a guarantee that an
operation will transpire within a certain period; a deterministic
interval. Real-time OS's have fancy tools to monitor if control
(application) threads are meeting their deterministic constraints
and adapt (or fail gracefully) as required. 'C' is the language of choice.

If you had maintained a specification that the injector control
had to operate at certain times, you would have put yourself in
the 'hard' real-time category, and would have to go through a
worst-case latency evaluation every time you added code.

Relaxing the spec as you did lets you stay in the 'soft' camp.
In testing you just need to verify you meet whatever periodicity
requirements you have.

enjoy,
--Kenny A.

Most of the processors I am familiar with disabling
external interrupts is an option by the asm programmer.
Not mandatory.

It was in the 6502, 68XXX, 8088, 8086, 286, 386.

That is not to say the  binary instructions could not take
more than one clock cycle.

Is that a feature of micro programmed RISC processors?
Since the asm instructions are made up from multi
micro instructions. I am not familiar with the RISC Atmel
on a asm level.

I can see  how a compiler could do that. If you are talking
C or any other language I can see (pardon the pun jd)
how the compiler could or would do that. ZBasic was
written in C ++ and that could be what the ZBasic programmer
was referring too in our conversation on the subject.
The assemblers that I know about do not automatically
disable interrupts for any single or multiple instruction
sequences. It is left up to the programmer.

If this is true I am a bit disappointed.
"You just shot an unarmed man." "He should have
armed himself" learned and written it in asm :)

Paul Lamar
-- 

The Rotary Engine NewsLetter. Powered by Linux.
ACRE NL web site. http://www.rotaryeng.net
Youtube key word PaulLamar2
Copyright 1998-2010 All world wide rights reserved.