Subject:
|
Re: multiplexor and legOS
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Tue, 5 Feb 2002 06:17:18 GMT
|
Reply-To:
|
Dick Swan <DICKSWA@SBCGLOBAL.nomorespamNET>
|
Viewed:
|
2108 times
|
| |
| |
Try the following code fragments. [Change to fixed spacing font so that it reads easily.] You should be able to find
what you need.
"Mark Falco" <> wrote in message news:Gr1MBL.Dop@lugnet.com...
<<..snip..>>
>
> Does anyone know what the proper assembly code would be? I've tried cuting and
> pasting from ds_handler but just locked up the RCX.
These are code fragment for handling sensors on 1-msec interrupt level and
for initiating an A-to-D scan.I've given C-code and generated assembly.You
need to let the sensors 'settle' before doing an A/D conversion. I think you
should find what you're looking for buried in these.
Useful declarations:
typedef enum // need the "(byte)' cast so that Hitachi compiler will fit it in a single byte!
{
tADCSRbitClear = (byte) (0),
tADCSRChannelSelect = (byte) (3 << 0), // select channels 0..3 within group
tADCSRGroupSelect = (byte) (1 << 2), // 0= channels 0-3, 1= channels 4-7
tADCSRClockSelect = (byte) (1 << 3), // 0= 266 states, 1= 134 states
tADCSRScanMode = (byte) (1 << 4), // 0= single mode, 1= scan mode
tADCSRADStart = (byte) (1 << 5), // starts/stops A/D conversion
tADCSRADIE = (byte) (1 << 6), // enable/disable A/D interrupt
tADCSREndFlag = (byte) (ubyte) (1 << 7) // indicates the end of A/D conversion
} TADCSR;
extern TADCSR IOPortADControlStatusRegister;
typedef enum // need the "(byte)' cast so that Hitachi compiler will fit it in a single byte!
{
p6bitClear = (byte) (0),
p6Sensor3Output = (byte) (1 << 0),
p6Sensor2Output = (byte) (1 << 1),
p6Sensor1Output = (byte) (1 << 2),
p6bit3 = (byte) (1 << 3),
p6SpeakerTimerOutput = (byte) (1 << 4),
p6LCDI2CClock = (byte) (1 << 5),
p6LCDI2CData = (byte) (1 << 6),
p6InfraredTimerOutput = (byte) (ubyte) (1 << 7)
} TPort6BitFields;
TPort6BitFields IOPort6DataRegister;
This is selected code extracted from my listing for 1-msec interrupt handler.
347: ///////////////////////////////////////////////////////
348: //
349: // One Msec Interrupt Handler [RAM]
350: //
351: ///////////////////////////////////////////////////////
352:
353: void ramOC1Ahandler1MsecTimerX()
01EC _ramOC1Ahandler1MsecTimerX: ; function: ramOC1Ahandler1MsecTimerX
..
..
..
357: if (nSensorRefreshMsecCounter <= 0)
01FA 6A08 MOV.B @_nSensorRefreshMsecCounter:16,R0L
<0000>
01FE 4E0A BGT L464
358: {
359: //
360: // Disable the power output to active [light, rotation] sensors.
361: //
362: // Use the delay in this routine to let them stabilize and then at the end of routine,
363: // start A/D conversion
364: //
365: IOPort6DataRegister &= ~(p6Sensor3Output | p6Sensor2Output | p6Sensor1Output);//disable
active power to sensors
0200 6A08 MOV.B @_IOPort6DataRegister:16,R0L
<0000>
0204 E8F8 AND.B #-8:8,R0L
0206 6A88 MOV.B R0L,@_IOPort6DataRegister:16
<0000>
020A L464:
366: }
..
.. remainder of 1-msec interrupt routine deleted.
..
This is code fragment for starting an A/D conversion. It's at the end of the 1-msec interrupt routine and uses the
inherent delay in the other work that has been done to settle the power output to the sensors.
619: // Diddle the AtoD control registers now that we've had some delay from the body of the
procedure
620: //
621: if (nSensorRefreshMsecCounter <= 0)
0454 6A08 MOV.B @_nSensorRefreshMsecCounter:16,R0L
<0000>
0458 4E12 BGT L497
622: {
623: //
624: // tADCSRADStart = Starts A/D conversion
625: // tADCSRADIE = Enable interrupt on end of A/D conversion
626: //
627: IOPortADControlStatusRegister |= tADCSRADStart | tADCSRADIE;
045A 6A08 MOV.B @_IOPortADControlStatusRegister:16,R0L
<0000>
045E C860 OR.B #96:8,R0L
0460 6A88 MOV.B R0L,@_IOPortADControlStatusRegister:16
<0000>
628: nSensorRefreshMsecCounter = kSensorRefreshPeriod - 1;
0464 F802 MOV.B #2:8,R0L
0466 6A88 MOV.B R0L,@_nSensorRefreshMsecCounter:16
<0000>
046A 400A BRA L498
046C L497:
629: }
630: else
631: --nSensorRefreshMsecCounter;
046C 6A08 MOV.B @_nSensorRefreshMsecCounter:16,R0L
<0000>
0470 1A08 DEC.B R0L
0472 6A88 MOV.B R0L,@_nSensorRefreshMsecCounter:16
<0000>
This is the interrupt routine called when A/D conversion is complete.
201: void ramAtoDhandlerX()
0154 _ramAtoDhandlerX: ; function: ramAtoDhandlerX
202: {
203: IOPortADControlStatusRegister &= ~(tADCSRADStart | tADCSRADIE);
0154 6A08 MOV.B @_IOPortADControlStatusRegister:16,R0L
<0000>
0158 E89F AND.B #-97:8,R0L
015A 6A88 MOV.B R0L,@_IOPortADControlStatusRegister:16
<0000>
204: IOPortADControlStatusRegister &= ~tADCSREndFlag;
015E 7900 MOV.W #_IOPortADControlStatusRegister:16,R0
<0000>
0162 7D007270 BCLR.B #7,@R0
205: IOPort6DataRegister |= sensorControlForIOPort6DataRegister; // this is a bit map of the
active
// sensors that need power.
// Power is re-enabled in this
step
0166 6A08 MOV.B @_sensorControlForIOPort6DataRegister:16,R0L
<0000>
016A 6A09 MOV.B @_IOPort6DataRegister:16,R1L
<0000>
016E 1489 OR.B R0L,R1L
0170 6A89 MOV.B R1L,@_IOPort6DataRegister:16
<0000>
206: nSystemTaskNeedExecuting |= maskTaskSensor;
0174 7900 MOV.W #_nSystemTaskNeedExecuting:16,R0
<0000>
0178 7D007000 BSET.B #0,@R0
207: return;
208: }
017C 5470 RTS // note: 'RTI' may be needed if using entries in interrupt jump table
|
|
1 Message in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|