heres the exercise.
description (page 2):
the DC motor can reach 8000rpm. The polarity of the voltage given to the motor that makes it turn clockwise or the other way, is chosen by the K1 relay.
The activation of the motor for clockwise (or reverse) movement is chosen from the PB6 and PB7 pins of PortB, which are codified from U4.
When d6(PB6)=1 and d7(PB7)=0 the motor turns clockwise.
When d6(PB6)=0 and d7(PB7)=1 the motor turns on the left.
The other 2 combinations will stop the motor.
In order to decodify and bring any output of U4 in logic '0', U4 must first be enabled, by putting the switch SW2B on the 'MOTOR' position. This will bring logic '0' in the pin 1 of U4 (in any other case the pin will 'climb' to +5V through the 4.7kOhm resistance)
Any combination of d6 and d7 (PORTB) that starts the motor, will bring logic '0' on pin 9 of U4. This results, through the high voltage of pin 15 of U3 and the relay K1, to ground one side of the motor and start its movement.
The combination that starts the motor (d6=0 and d7=1) will bring in logic '0' the pin 5 of U4. This will enable relay K1 through pin 16 of U3, it will reverse its contacts and the polarity of the supplier of the motor resulting a change in its rotation.
While the motor rotates, its propeller moves through a source of infra-red ray (D1) and an infra-red ray detector (D2). The change in the current that passes through the detector is enough to bring pin 1 of U5B in logic '1' that will give a signal, 3 times per rotation in the line PA4 of PORT A. This happens when SW4A is in position 'SPEED ON', which connects the output of pin 2 of U5 with the line PA4 of PORT A.
The exercise asks to:
Write a program the will move the motor with the speed determined from the pins d0-d3 of PORT A. The motors speed can be between 1000-7000 rpm.
The code is in page 5 of the pdf file.
Its all good till the line of the code (in the main program) that prompts in the GETRPM subroutine, but I don't quite understand the subroutine.
INIT____MOVEA.L___#$800001,A0_____; Starting address of PI/T
________MOVE.B____#$00,$4(A0)_____; make port A input
________MOVE.B____#$FF,$6(A0)_____; make port B output
SPEED__MOVE.B____$10(A0),D2______; move the state of port A on D2
________ANDI.B____#$0F,D2_________; Take only d0-d3 pins that determine the speed
________MULS______D3,D2___________; D2=D3*D2 (decimal of the pins (0-7)* 1000 for the speed of the motor (1000 to 7000 rpm)
________BSR_______GETRPM__________; Branch to subroutine GETRPM
GETRPM_MOVE.W____#$800,D1________; D1=$800 (2048 DECIMAL)
________BEQ_______RPM4____________; IF Z=1 GO TO RPM4 ELSE CONTINUE
________BTST______#4,$10(A0)______; check D4 of port A
________BNE_______RPM1____________; if Z=0 go to RPM1 else continue
________BEQ_______RPM2____________; might be BNE ???
It seems that the subroutine is used for the detector of the infra-red ray, so it can read the speed, but how exactly is this done?
It does 3 checks. The source of the infra-red ray, gives a signal, 3 times per rotation.. I cant understand why the subroutine starts by putting on D1 $800 and how it continues.
BTW, the code might be wrong or missing some lines.