Download Part I Integrators Manual

Transcript
CHAPTER 7. HAL TUTORIAL
7.3.3
50
Making realtime code run
To actually run the code contained in the function siggen.0.update, we need a realtime thread.
The component called threads that is used to create a new thread. Lets create a thread called
test-thread with a period of 1mS (1000000nS):
halcmd: loadrt threads name1=test-thread period1=1000000
Let’s see if that worked:
halcmd: show thread
Realtime Threads:
Period
FP
Name
(Time, Max-Time)
999849 YES test-thread
( 0, 0 )
It did. The period is not exactly 1000000nS because of hardware limitations, but we have a thread
that runs at approximately the correct rate, and which can handle floating point functions. The
next step is to connect the function to the thread:
halcmd: addf siggen.0.update test-thread
Up till now, we’ve been using halcmd only to look at the HAL. However, this time we used the
addf (add function) command to actually change something in the HAL. We told halcmd to add the
function siggen.0.update to the thread test-thread, and if we look at the thread list again, we
see that it succeeded:
halcmd: show thread
Realtime Threads:
Period
FP
Name
(Time, Max-Time)
999849 YES test-thread
( 0, 0 )
1 siggen.0.update
There is one more step needed before the siggen component starts generating signals. When the
HAL is first started, the thread(s) are not actually running. This is to allow you to completely
configure the system before the realtime code starts. Once you are happy with the configuration,
you can start the realtime code like this:
halcmd: start
Now the signal generator is running. Let’s look at its output pins:
halcmd: show pin
Component Pins:
Owner Type Dir
32769
float OUT
32769
float OUT
32769
float OUT
32769
float OUT
32769
float OUT
halcmd: show pin
Component Pins:
Owner Type Dir
32769
float OUT
32769
float OUT
32769
float OUT
32769
float OUT
32769
float OUT
Value
Name
2.12177e-01 siggen.0.cosine
-5.64055e-01 siggen.0.sawtooth
9.79820e-01 siggen.0.sine
-1.00000e+00 siggen.0.square
1.28110e-01 siggen.0.triangle
Value
Name
5.19530e-01 siggen.0.cosine
6.73893e-01 siggen.0.sawtooth
-8.54452e-01 siggen.0.sine
1.00000e+00 siggen.0.square
3.47785e-01 siggen.0.triangle