View Full Version : A Question for Mike Powell
MechDave
07-11-2009, 05:30 AM
Hi Mike,
I am having trouble with understanding your op command summary for the gyro compass, it may be I don't know enough about the subject. Am I on the right track when I am thinking that for command Set Motor Position for example, Bytes [0:4] are the unique identifier for this instrument,(can be 4 bytes made up of any sequence of 1 and 0?), now byte 5 is set to 1 is that 00000001? and bytes [6:7] is motor position.
Now I am having trouble sorting out what exactly I should program for motor position, eg: what is forward and what is reverse, what is take 10 steps forward etc. Could you please lend me a little hand as this is got my poor brain boggling at the moment as I am not too flash with assembler, I only used it once whilst attending uni :)
Cheers,
Dave...
Mike.Powell
07-11-2009, 12:04 PM
Hi Dave,
The forward, backward, and take a step stuff is all hidden in the firmware. The set motor position need only be loaded with the position where you want the motor to end up.
The project is designed with a 400 step per revolution motor in mind. It is half-stepped to give 800 discreet positions which are referred to as positions 0 to 799. When powered on or reset, the firmware rotates the motor until the flag on the motor shaft goes through the gap in the optical interrupter. This is position 0.
For simplicity, let's assume you have the DG compass card set such that North is aligned with position 0.
If you wanted the compass card to rotate to the 90 degree position, you would send a set motor position command with a value of 200. One of the micro controller timers periodically wakes up the firmware to watch over the motor. Firmware compares the current motor position (0) with the desired motor position (200), determines the shorter direction to turn the motor, takes a single half-step, and changes the current motor position variable to "1". The next time the timer wakes up the firmware, it will move the motor to position 2, and so on until it reaches position 200.
Had you wanted to rotate the compass card to the 270 degree position, you would have sent a position value of 600, and the firmware would have moved the motor from position 0 to position 799, choosing to rotate the opposite direction.
The format of the command string is as you have presented it:
Bytes 0 to 4 are the instrument identifier. They can be any string of 1s and 0s. However, I typically use five ascii characters because it's easier to remember. I believe "ZZZ99" and "DG001" are both used in the project.
Byte 5 is the command byte. The set motor position command is the numeric value 1 which in binary is "00000001"
Bytes 6 and 7 contain the desired motor position. Because there are 800 positions, we need 10 bits. Since a byte only has 8 bits, we need 2 bytes.
MechDave
07-11-2009, 11:19 PM
Mike,
That clears up my confusion completley, I wrote out the contents of several calls to the gauge this morning using binary representation. It all makes sense :), thanks for the clarification, much appreciated.
Cheers,
Dave...
Tripacer
07-11-2009, 11:56 PM
Mike,
Thanks for the clear explaination. While I understand the choice of turning the stepper motor the shortest direction. What happens in the case that the airplane was actually turning in the "other" direction? couldn't there ba a condition when the compass went in the wrong direction without some notion of where we were at the last position and which way the aircraft is turning? I suppose, however, that in all actuality that the rate that data was being sent to the instrument would make the new heading values very small anyway.
William, Tripacer Builder
Mike.Powell
07-12-2009, 12:22 AM
William,
You might have a condition in which the desired heading is changing faster than the motor can respond. Given the speed of the motor and typical flight parameters, I think this would most likely be an error condition in the simulator. Nonetheless, the firmware reacts on an interrupt by interrupt basis, and would not get confused. It just keeps trying to move the motor position into alignment with the incoming data.
MechDave
10-04-2009, 04:06 AM
G'day Mike,
I am having a little trouble working out how to adjust the MAXPOS variable in the INITIALIZE routine for different steppers in the Gyro Compass project. Could you please explain to me how this is achieved in a little more detail?
The problem being is that I can only get a 1.8 deg/step motor for a reasonable price. This would then turn out to be 400 steps half stepped which will give me roughly 0.9 steps per degree which I am hoping will be enough resolution, considering the compass rose has minimum markings of 5 degrees.
Cheers,
Dave...
Mike.Powell
10-04-2009, 12:58 PM
Hi Dave,
The PIC assembler treats "MAXPOS" as a byte address. "MAXPOS+1" is the address of the next byte. Since the 400 position stepping motor has 800 half-stepped positions, two bytes are required to hold the value of the maximum position which is 799. (Positions range from 0 to 799.) MAXPOS+1 is the high byte, so if MAXPOS+1 is 3 and MAXPOS is 31, the value of the maximum position is 3*256 + 31 = 799. Similarly, HALFWAY+1 is 1 and HALFWAY is 144, and 1*256 + 144 = 400.
Converting to a 200 step per rev motor means changing to a range of 0 to 399, and a half way position of 200. MAXPOS+1 becomes 1; MAXPOS becomes 143 (1*256 + 143 = 399). HALFWAY+1 becomes 0; HALFWAY becomes 200.
MechDave
10-04-2009, 08:29 PM
Thanks Mike,
I wondered why I couldn't make head nor tail of it! Since your post I have found the 16 bit variable declaration in the Predko. This helped heaps, especially making the watch window reference MaxPos and HalfWay as a 16 bit variable and not a 8 bit variable :oops: Your explanation helped make it gel quite well :)
Thanks heaps for your patience,
Dave...