To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 1869
1868  |  1870
Subject: 
Better assembly code
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Fri, 4 Apr 1997 23:23:58 GMT
Original-From: 
Chuck McManis <CMCMANIS@FREEGATE.stopspammersNET>
Reply-To: 
cmcmanis@freegateNOSPAM.net
Viewed: 
1467 times
  
I went home and got my Pink book, the menemonics on this 'software
output only' UART are now correct (assume PORTA bit 7 (PAI) as the
output pin)

;
; Called with character to send in A
; Destroys A, B, and X
;
serout::
SEI ; disable interrupts
LDX #$1000 ; point at the I/O registers
LDAB #9 ; send 9 bits (8 data + 1 stop)
cycles BCLR 0,X, #$80 ; send the start bit
(3) loop1: PSHB ; save B register
(2) ** NOP ; See text below
(2) LDAB #delay ; Loop delay constant
(2) loop2: DECB ; decrement by one
(3) BNE loop2 ; wait
(4) PULB ; get B back
(2) LSLA ; Shift A left into the Carry bit
(3) BCS onebit ; if carry bit set output a '1'
(7) BCLR 0,X #$80 ; else turn off bit 7
(3) BRA cont ; do the delay loop
(7) onebit: BSET 0,X #$80 ; turn on the bit
(3) BRA cont ; (for symmetry through the loop)
(2) cont: ORAA #1 ; Set LSB to 1
(2) DECB ; All bits sent?
(3) BNE loop1 ; if not send another one.
CLI ; re-enable interrupts
RTS

Using the cycle counts on the left you can see that one 'pass'
through the loop is going to take 31 + 5 * delay cycles through
the loop (not counting the NOP). Since the loop needs to take
104.1666 uS and a cycle is 500 ns, we need 208.33 cycles to get
the correct bit timing. Which using our code would mean a delay
constant of 35.46 :-) Which we can't do, but if our loop was
'33 + 5 * delay' it would work out to a delay of 35 exactly.
So setting delay to 35 we get 208 cycles, which is a duration
of 104uS which is a baud rate of 9615 (or approx .16% too fast
but this is well within the tolerances of the Mini-SSC.

Unfortunately to maintain the timing relationship we have to
disable interrupts (the code will execute in 1.04 mS which
means that the system tick timer interrupt will fire in the
middle of it, unless interrupts are disabled.) So if you are
running motors or playing tones they could be adversely affected
by sending characters.

The delay constant for 2400 baud is 160 but then interrupts are
disabled for 4.16 mS which is even harder on the interrupt routines.

An alternative is to put another PIC between the 68HC11 and the
SSC acting as a high speed serial interface. Using either the SPI
port or bit banging again you can transfer three bytes (needed to
position one servo) at high speed to the intermediate PIC which
would turn around and send them at 9600 baud to the mini-SSC. The
new 8 pin 12000 series PIC would be good for this type of work.

--Chuck

--
cmcmanis@netcom.com              http://www.professionals.com/~cmcmanis
All opinions in the non-included text above are the sole opinions of
the author.



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR