logo
background
 Home and Links
 Your PC and Security
 Server NAS
 Wargames
 Astronomy
 PhotoStory
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>
[Definition] [Power on  detail] [Main loop detail] [Joystick subroutine]

Definition

The code consists of two main parts with a number of subroutines.

The two parts are:-

Power on / Reset calibration.
Measure and set Joystick resistance values (center off, max/min pan/tilt). It's possible that the push-buttons will also need to be measured, so the code will wait for the 'Start' push button - when 'sttart' is seen, exit power-on and enter Main loopp (on 'inactive' mode).
 
Main loop.
When 'inactive', check for Joystick/button activation, when found send code to CCTV mount and eneter 'active' mode. When active, check for Joystock/button release / stop button press, when found send 'stop' code to CCTV and eneter 'inactive' mode.

The subroutines are :-

Measure Joystick (returns code, pan nibble, tilt nibble, 0x00 = center, 0xFF = push-button)
Second level subroutine = measure count (2 entry points, pan/tilt), can be called directly (from power-on code) for 'raw' values
 
Measure push button (returns switch, 0x00 = none, bits 1-7 switch (bit 7 = Stop/Reset)
Second level subroutine = measure count, can be called directly (from power-on code) for 'raw' values
 
Send control packet to TS485 serial link (takes parameter 'control' byte). The send Subroutine calculates the XOR chedcksum as it transmits.
Second level sub-routine = send byte

Subroutines return values in the Accumerlator ('Wreg')

[top]

Power on (calibration) detail

At power-on the Joystick will be in the 'zero' (mid) position. So both axis can be measured and the 'zero' resistance (count) set

First the PIC sets various 'default' values (counter/timer pre-scaler etc.).
 
At power-on, all 4 i/o pins will have been set to 'input' mode. GP2 will be set to '1' and then as an output, which ensures the RS485 serial link is held in the 'idle' state (this also lights the 'Activity' LED and charges the 'button detect' capacitor)
 
The Joystick 'center' calibration values will then be measured (using GP1 and GP0).
 
The PIC code next turns off the 'Activity' LED (GP2 set to weak-pull-up input) and waits for the Joystick 'zero' resistance to change (i.e. for the user to move the Joystick to the 'Tilt up' maximium).
 
When the resistance changes, the 'activity' LED is turned on (GP2 set '1' output) and a number of measurements made for 'Tilt up' maximium.
 
The 'activity' LED is turned off again, after which the code waits for the Joystick to return to the 'zero' resistance position.
 
The code then waits for the resistance to change again, this time for the 'Tilt down' maximium, and cycles through as above (and then again for Pan Left and Right calibration). The 6 calibration values are stored.
 
Note: Immediately after the LED is turned off, a check can be made for a 'Reset' button press (if not pressed, the code will 'time out', as the button capacitor fails to discharge). If Reset is found, the code will start the power-on sequence again.
 
Finally, the code loops checking for push-buttons press. If start' is found, the code enters the Main Loop. If anything else, the value is stored (as one of the 6 push-button calibration)

[top]

Main loop detail

[top]

Joystick subroutine

 

[This is the last page in the "PIC projects" topic. Use the Navigation menu, left, to select a new Top Topic]

[top]