New Products Flash Sale
Thread Tools
Old Feb 11, 2006, 04:00 PM
Ron van Sommeren is offline
Find More Posts by Ron van Sommeren
homo ludens modellisticus
Ron van Sommeren's Avatar
Netherlands, GE, Nijmegen
Joined Feb 2001
12,052 Posts
Forward and backward controller:
http://www.fmx.dk/projects/mc_pic16/...ontroller.html
Ron van Sommeren is offline Find More Posts by Ron van Sommeren
Reply With Quote
Sign up now
to remove ads between posts
Old Jun 27, 2006, 12:13 PM
stefanv is offline
Find More Posts by stefanv
MotoCalc Developer
stefanv's Avatar
Moorefield, Ontario, Canada
Joined Mar 2001
315 Posts
Please note that www.capable.ca/rcstuff/ and www.capable.on.ca/rcstuff/ have changed to www.stefanv.com/rcstuff/

I've also added a copy of the ESC design I did for QuietFlyer, a brushed ESC with BEC and Brake, at www.stefanv.com/rcstuff/escboth.html

Stefan
stefanv is offline Find More Posts by stefanv
Reply With Quote
Old Jun 28, 2006, 11:24 AM
soren is offline
Find More Posts by soren
Senior Member
soren's Avatar
Denmark
Joined Sep 2000
173 Posts
Hi

A new forward/reverse speed controller:
Look at http://users.cybercity.dk/~ccc16084/ follow the “electronic” link

Best regards
Soren
soren is offline Find More Posts by soren
Reply With Quote
Old Nov 05, 2006, 07:57 AM
Ron van Sommeren is offline
Find More Posts by Ron van Sommeren
homo ludens modellisticus
Ron van Sommeren's Avatar
Netherlands, GE, Nijmegen
Joined Feb 2001
12,052 Posts
http://users.cybercity.dk/~ccc16084/el.htm

Forward/reverse:
http://users.cybercity.dk/~ccc16084/frspeed.htm
Ron van Sommeren is offline Find More Posts by Ron van Sommeren
Reply With Quote
Old Apr 17, 2007, 01:54 PM
Ron van Sommeren is offline
Find More Posts by Ron van Sommeren
homo ludens modellisticus
Ron van Sommeren's Avatar
Netherlands, GE, Nijmegen
Joined Feb 2001
12,052 Posts
Added:
http://www.rcgroups.com/forums/showthread.php?t=190829
Ron van Sommeren is offline Find More Posts by Ron van Sommeren
Reply With Quote
Old Nov 25, 2008, 05:14 PM
Ron van Sommeren is offline
Find More Posts by Ron van Sommeren
homo ludens modellisticus
Ron van Sommeren's Avatar
Netherlands, GE, Nijmegen
Joined Feb 2001
12,052 Posts
Added:
http://wb8lga.atco.tv/
-> Home made RC boat motor controller
Ron van Sommeren is offline Find More Posts by Ron van Sommeren
Reply With Quote
Old Jan 08, 2009, 07:58 AM
Ron van Sommeren is offline
Find More Posts by Ron van Sommeren
homo ludens modellisticus
Ron van Sommeren's Avatar
Netherlands, GE, Nijmegen
Joined Feb 2001
12,052 Posts
Added
http://www.e-radiocontrol.com.ar/dow...20Controls.pdf
Ron van Sommeren is offline Find More Posts by Ron van Sommeren
Reply With Quote
Old Jan 09, 2009, 12:32 PM
OldMann is offline
Find More Posts by OldMann
Registered User
Romania
Joined Dec 2006
37 Posts
http://www.pt-boat.com/electric/electric.html
OldMann is offline Find More Posts by OldMann
Reply With Quote
Old Jan 09, 2009, 07:14 PM
Ron van Sommeren is offline
Find More Posts by Ron van Sommeren
homo ludens modellisticus
Ron van Sommeren's Avatar
Netherlands, GE, Nijmegen
Joined Feb 2001
12,052 Posts
Added, a design with reverse:
http://www.rcgroups.com/forums/showt...2&page=2&pp=10
Ron van Sommeren is offline Find More Posts by Ron van Sommeren
Reply With Quote
Old Jul 21, 2015, 02:14 PM
Ron van Sommeren is offline
Find More Posts by Ron van Sommeren
homo ludens modellisticus
Ron van Sommeren's Avatar
Netherlands, GE, Nijmegen
Joined Feb 2001
12,052 Posts
Brushed controller kits, also with reverse
www.modellbau-regler.de/shop/index.php?language=en

Vriendelijke groeten Ron
Ron van Sommeren is offline Find More Posts by Ron van Sommeren
Reply With Quote
Old Jul 21, 2015, 07:57 PM
Takao Shimizu is offline
Find More Posts by Takao Shimizu
Registered User
Tokyo, Japan
Joined Nov 2002
903 Posts
Arduino Brushed DC motor controller, also with reverse

Arduino Sketch's PWM bug report is here
https://github.com/arduino/Arduino/issues/2455

Takao
Takao Shimizu is offline Find More Posts by Takao Shimizu
Reply With Quote
Old Jul 21, 2015, 09:54 PM
vollrathd is online now
Find More Posts by vollrathd
Registered User
vollrathd's Avatar
Joined Jan 2007
1,740 Posts
Wow, an old Brushed ESC Thread

This thread goes way back.

I built up a number of different MicroChip PicChip ESCs that evolved to this project in 2001. Then the brushless motors took over, and this thing became pretty much obsolete.

The Microcontroller is basically a brush type ESC with seven other functions, like providing servo signals with digital readout and so on. This project wound up in Servo magazine years ago.

Attached are photos of what the final unit looked like. I built up several dozen of them, and all worked perfectly.

Code:
Multimode ESC Control with 7 other functions
;10-02-98		;START OF PROGRAM 
;10-28-98		;TIME SPENT ON OPTOMIZING PULSE WIDTH
;10-29-98		;PULSE WIDTH OPTIMIZED
;11-25-98		;SET UP FULL OFF, AND FULL ON COMMANDS
;12-01-98		;CONTINUE ON WITH FULL OFF
;12-03-98		;FULL PROGRAM WORKS PROPERLY
;12-09-98		;START OF TRANSMITTER INITIALIZATION
;12-30-98		;CHANGED TO MASTER-SLAVE PROGRAM
;12-31-98		;MASTER PROGRAM IS WORKING. OUTPUT IS 0-3E
;12-31-98               ;FULL ON SIGNAL OK, NO SIGNAL NOT DETECTED YET
;01-01-99		;MASTER CPU ALL FINISHED
;11-26-00		;REWORK FOR SINGLE 16F873 CHIPS
;12-19-00		;ALL WORKS, NOW ADDING BRAKE FUNCTION
;01-19-01		;ADD MOTOR SINGING PROGRESS RATE
;01-20-01		;ADDED ERROR LOG
;02-04-01		;ADDED LOW BATTERY POWERDOWN
;02-21-01		;ADDING MULTIFUNCTION CAPABILITY 
;02-21-01		;ADDING SERVO DRIVER CAPABILITY
;03-03-01		;FIXED MPU CRASH ON 3 MS LONG PULSE
;03-03-01		;CRASH CAUSED BY OVERRANGE LOOKUP TABLE
;04-04-01		;ADDED DIRECT READBACK FUNCTION
;04-09-01		;MAJOR CHANGES TO INIT SPEED CONTROL
;04-11-01		;FIXED ERROR LOGGING AND LONG PULSE PROBLEMS
;04-12-01		;CHANGE ERROR EXPORT TO ONCE EVERY 5 CYCLES
;05-15-01		;ADDED SPEED CONTROL FLAG OUTPUT
;05-24-01		;ADDED SPEED CONTROL ARMED AND VALID SIGNAL
;06-03-01		;ADDED PORTB 0,1,2 BEEP STATUS OUTPUT
;07-12-01		;CHANGED TIMING FOR AM RADIOS
;07-15-01		;ADDED PULSE MILLISECOND READ FUNCTION
;07-23-01		;ADDED SERVO 'BANG-BANG' AND RAMP TESTS
;09-07-01		;ADDED ERROR OUT ON PIN 26 FOR STD ESC
;04-10-02		;ADDED ERROR OUT ON PIN 24, 25 FOR STD ESC
;PORTA,3,4,5 ARE INPUTS FOR FUNCTION COMMANDS ON POWER UP
	LIST	P=PIC16F873
	INCLUDE	"P16F873.INC"   
 

#DEFINE	LCDOUT	PORTB
#DEFINE	LCDRS	PORTC,6
#DEFINE LCD_E	PORTC,7
#DEFINE	DATAIN	PORTC,5
#DEFINE	DATASTB	PORTC,4
#DEFINE PAGE1   BSF     STATUS,RP0      ;SET UP FOR HIGH MEMORY
#DEFINE	PAGE0	BCF	STATUS,RP0
#DEFINE	PULSEIN	PORTC,3
#DEFINE	SIGOUT	PORTC,3
#DEFINE	BRAKOUT	PORTC,7
#DEFINE	INPUTOK	PORTB,6
#DEFINE PULSEHI	PORTC,0
#DEFINE SERIALF	PORTC,4
#DEFINE SERIALD	PORTC,5
#DEFINE	ESCARM  PORTB,7		;SHOW MOTOR IS ARMED
#DEFINE	ERROR_0	PORTB,7	;ACTIVE ERROR INDICATION
#DEFINE ERROR_1	PORTB,5	;ALERT FOR 15  FRAME LOSS ON ESC
#DEFINE ERROR_2	PORTB,4	;ALERT FOR 50  FRAME LOSS ON ESC
#DEFINE ERROR_3	PORTB,3	;ALERT FOR 200 FRAME LOSS ON ESC

#DEFINE	HPAGE	BSF	PCLATH,3
#DEFINE	LPAGE	BCF	PCLATH,3

;XMTR	STICK	TRIM	MS TIME
;FM	MIN	MIN	1.09	90	5AH
;FM	MIN	MAX	1.31	113	71H
;FM	MAX	MIN	1.87	164	A4H
;FM	MAX	MAX	2.11	187	BB
;**************************************************************************
RAM 	EQU    	0X30
TOPBYTE	EQU	RAM+01	;USED FOR TIMING 2.0 MS
BOTBYTE	EQU	RAM+02	;USED FOR TIMING 1.0 MS
RAMPCNT	EQU	RAM+03	;RAMP TIMER FOR MOTOR PULSE WIDTH MODULATION
SRTIMER	EQU	RAM+04	;RAMP TIMER FOR SERVO PULSE WIDTH MEASUREMENT
OFFCNT	EQU	RAM+05	;SERVO OFF SIGNAL TIMER		
DELAY1	EQU	RAM+06
DELAY2	EQU	RAM+07
DELAY3	EQU	RAM+08
TMPCNT	EQU	RAM+09	;RAMPCNT FOR GET PULSE WIDTH 
STROBE	EQU	RAM+0A
H_BYTE	EQU	RAM+0B
L_BYTE	EQU	RAM+0C
MULCND	EQU	RAM+0D
MULPLR	EQU	RAM+0E
DIVISOR	EQU	RAM+0F
COUNT	EQU	RAM+10
ACCALO	EQU	RAM+11
NOSIG1	EQU	RAM+12
NOSIG2	EQU	RAM+13
AVERAGE	EQU	RAM+14
AVERCNT	EQU	RAM+15
L_BYTER	EQU	RAM+16
H_BYTER	EQU	RAM+17
TEMP	EQU	RAM+18
BRAKETM	EQU	RAM+19
STARTUP	EQU	RAM+1A
ERRORLO	EQU	RAM+1B
ERRORHI	EQU	RAM+1C
SHIFT	EQU	RAM+1D
SHFTCNT	EQU	RAM+1E
   
DIGIT1	EQU	RAM+1F
DIGIT2	EQU	RAM+20
DIGIT3	EQU	RAM+21
DIGIT4	EQU	RAM+22
DIGIT5	EQU	RAM+23
BCOUNTS	EQU	RAM+24
BTEMP	EQU	RAM+25
R0	EQU	RAM+26
R1	EQU	RAM+27
R2	EQU	RAM+28
FLAG	EQU	RAM+29
TEST1	EQU	RAM+2A
TEST2	EQU	RAM+2B
ERRORCT	EQU	RAM+2C
;**********************************************************************

;START OF PROGRAM
	ORG     0X00	        ;START ADDRESS 0
	NOP	
	GOTO	START

LOOKUP 	ADDWF	PCL,1

	RETLW	D'250'		;STEP 00
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'		;STEP 10
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'		;STEP 20
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'		;STEP 30
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW   D'00'
	RETLW	D'00'
	RETLW	D'00'
	RETLW	D'00'		;STEP 40
	RETLW	D'00'
	RETLW   D'00'
	RETLW	D'00'
	RETLW	D'00'
	RETLW	D'00'
	RETLW	D'00'
	RETLW   D'00'
	RETLW	D'00'
	RETLW	D'00'
	RETLW	D'00'		;STEP 50 
	RETLW	D'00'
	RETLW   D'00'		;PWR0
	RETLW	D'03'		
	RETLW	D'06'		
	RETLW	D'08'		
	RETLW	D'11'		
	RETLW   D'13'
	RETLW	D'16'
	RETLW	D'18'
	RETLW	D'21'		;STEP 60 
	RETLW	D'23'
	RETLW   D'26'		;PWR10
	RETLW	D'28'
	RETLW	D'30'
	RETLW	D'33'
	RETLW	D'35'
	RETLW   D'37'
	RETLW	D'40'
	RETLW	D'42'
	RETLW	D'43'		;STEP 70 
	RETLW	D'45'
	RETLW   D'47'		;PWR20
	RETLW	D'48'
	RETLW	D'49'
	RETLW	D'50'
	RETLW	D'51'
	RETLW   D'52'
	RETLW	D'53'
	RETLW	D'54'
	RETLW	D'55'		;STEP 80 
	RETLW	D'56'
	RETLW   D'57'		;PWR30
	RETLW	D'58'
	RETLW	D'58'
	RETLW	D'59'
	RETLW	D'60'
	RETLW   D'61'
	RETLW	D'62'
	RETLW	D'62'
	RETLW	D'63'		;STEP 90 
	RETLW	D'64'
	RETLW   D'65'		;PWR40
	RETLW	D'66'
	RETLW	D'67'
	RETLW	D'68'
	RETLW	D'68'
	RETLW   D'69'
	RETLW	D'69'
	RETLW	D'70'
	RETLW	D'71' 		;STEP 100
	RETLW	D'71'
	RETLW   D'72'		;PWR50
	RETLW	D'73'
	RETLW	D'74'
	RETLW	D'74'
	RETLW	D'75'
	RETLW   D'76'
	RETLW	D'76'
	RETLW	D'77'
	RETLW	D'78'		;STEP 110
	RETLW	D'78'
	RETLW   D'79'		;PWR60
	RETLW	D'79'
	RETLW	D'80'
	RETLW	D'80'
	RETLW	D'81'
	RETLW   D'81'
	RETLW	D'82'
	RETLW	D'82'
	RETLW	D'83'		;STEP 130
	RETLW	D'83'
	RETLW   D'84'		;PWR70
	RETLW	D'84'
	RETLW	D'85'
	RETLW	D'85'
	RETLW	D'86'
	RETLW   D'86'
	RETLW	D'87'
	RETLW	D'88'
	RETLW	D'88'		;STEP 140
	RETLW	D'89'
	RETLW   D'90'		;PWR80
	RETLW	D'90'
	RETLW	D'91'
	RETLW	D'91'
	RETLW	D'92'
	RETLW   D'92'
	RETLW	D'93'
	RETLW	D'93'
	RETLW	D'94'		;STEP 150
	RETLW	D'94'
	RETLW   D'95'		;PWR90
	RETLW	D'95'
	RETLW	D'96'
	RETLW	D'96'
	RETLW	D'97'
	RETLW   D'97'
	RETLW	D'98'
	RETLW	D'98'
	RETLW	D'99'		;STEP 160
	RETLW	D'99'
	RETLW   D'100'		;PWR100
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'		;STEP 170
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'		;STEP 180
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'		;STEP 190
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'		;STEP 200
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'		;STEP 210
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'		;STEP 220
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW   D'100'
	RETLW	D'100'
	RETLW	D'100'
	RETLW	D'100'		;STEP 230
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'		;STEP 240
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'		;STEP 250
	RETLW	D'250'
	RETLW   D'250'
	RETLW	D'250'
	RETLW	D'250'
	RETLW	D'250'
  
;BELOW IS START OF PROGRAM
START	NOP			;SETUP AND INITIALIZE MASTER CHIP
       	PAGE1      		;SET UP FOR HIGH MEMORY
	MOVLW	B'11111111'	;BITS 3&4 INS, ALL ELSE OUTS
 	MOVWF	TRISC		;BIT C4 IS IN, ALL ELSE OUTS
	CLRF	PORTA		;CLEAR OUTPUT LATCHES
	MOVLW	0X06		;SET UP PORT A AS DIGITAL
	MOVWF	ADCON1		;AND SET IT UP
	MOVLW	B'00111111'	;0=ANALOG, 4=PULSE IN
	MOVWF	TRISA
 	CLRF	TRISB
 	PAGE0			;AND RESET FOR LOW MEMORY
	CLRF	FLAG		;CLEAR FLAG FOR DUAL RATE
	CLRF	PORTB		;CLEAR LCD DISPLAY
;*******************************************************************
;TEST FOR COMMAND INPUTS ON PORTA, 3,4,5 HERE
;*******************************************************************
	BCF	ESCARM		;SHOW MOTOR IS CLEAR
	MOVFW	PORTA
	ANDLW	B'00111000'	;CLEAR FOR BRANCH COMMANDS
	BZ	RUNMOTR
	MOVWF	COUNT		;SAVE PORT DATA
	MOVLW	B'00011000'	;TEST FOR FIRST BIT
	XORWF	COUNT,0		;IS IT BIT 4 & 5?
	BZ	RUNSERV
	MOVLW	B'00010000'	;TEST FOR FIRST BIT
	XORWF	COUNT,0		;IS IT BIT 5
	BZ	RUNSERVA	;GO TO SLOW RUNSERV
	MOVLW	B'00001000'	;TEST FOR FIRST BIT
	XORWF	COUNT,0		;IS IT BIT 4?
	BZ	RUNREAD
	MOVLW	B'00100000'	;TEST FOR FLIGHT ERRORS
	XORWF	COUNT,0		;IS IT ERRORS?
	BZ	ERRORLG
	MOVLW	B'00101000'	;IS IT VOLTMETER?
	XORWF	COUNT,0		;
	BZ	VOLTMTR		;GOTO	VOLTMTR
	MOVLW	B'00110000'	;IS IT PULSEM?
	XORWF	COUNT,0
	BZ	PULSEM
	MOVLW	B'00111000'	;IS IT LAST COMMAND?
	XORWF	COUNT,0
	BZ	SERVOCYCLE			

BADINPT	BSF	PORTC,6
	CALL	DELAY
	BCF	PORTC,6
	CALL	DELAY
	GOTO	BADINPT
;*******************************************************************
;BELOW IS THE COMPLETE ROUTINE FOR THE PWM SPEED CONTROL
;*******************************************************************
RUNMOTR	PAGE1
	MOVLW	B'00001000'	;BITS 3&4 INS, ALL ELSE OUTS
 	MOVWF	TRISC		;BIT C4 IS IN, ALL ELSE OUTS
	PAGE0
	BCF	PORTC,2		;KILL MOTOR
	BCF	BRAKOUT
;TEST FOR VALID TRANSMITTER FOR 40 FRAMES, 2 SECONDS
RESTINT	MOVLW	0X30		;INIT START COUNTER
	MOVWF	STARTUP		;SET START COUNTER
INITIAL	CALL	GETPULSE
 	MOVLW	0X40
	SUBWF	TMPCNT,0	;TEST AGAINST MINIMUM VALID VALUE
	BNC	RESTINT		;DUD, RESTART
	MOVLW	0X90		;TEST AGAINST MAX VALUE
	SUBWF	TMPCNT,0
	BC	RESTINT		;DUD, RESTART
	DECF	STARTUP,1	;DECREMENT COUNTER
	BNZ	INITIAL
	MOVLW	D'250'		;SETS UP FRAME RATE
	PAGE1
	MOVWF	PR2	 	;FOR BOTH PWM SYSTEMS
	PAGE0

;**************************************************************************
;INITIALIZATION OF TRANSMITTER RANGE FOR 1-2 MS SERVO INPUT    
NOMAX				
	CALL	GETPULSE	;TEST FOR BELOW 1/2 STICK
	CALL 	SETDLY
	MOVLW	D'120'
	SUBWF	TMPCNT,0
	BNC	LOWSTK1
	GOTO	NOMAX		;NOT BELOW 1/2 STICK, LOOP AGAIN
LOWSTK1	CALL	PWMSPCL
	BSF	PORTB,0		;SET BEEP#1
	CALL	MTRSING		;MAKE MOTOR SING
LOWSTK	CALL	GETPULSE	;GET PULSE SIGNAL W&TMPCNT HAS DATA
 	CALL	SETDLY 
	MOVLW	D'135'		;TEST AGAINST 60% THROTTLE
	SUBWF	TMPCNT,0	;TMPCNT HAS DATA, >HEX34
	BC	GOTMOV1
	GOTO	LOWSTK		;STICK NOT MOVED PAST 60% THROTTLE
GOTMOV1	MOVLW	0X20
	MOVWF	COUNT		;SAVE COUNTER
;GOT STICK PAST 60% NOW CONTINUE ON WITH PROGRAM
GOTMOVE
	CALL	GETPULSE	;TMPCNT +W HAS DATA
	MOVFW	TMPCNT		;GET DATA
	MOVWF	STROBE		;SAVE IT
	CALL	SETDLY		;CALL FAST DELAY
	CALL	GETPULSE
	MOVFW	TMPCNT 
	SUBWF	STROBE,0	;TEST FOR SAME VALUE?
	BNZ	GOTMOVE		;NO MATCH, DO IT AGAIN
	DECF	COUNT,1		;ITS A MATCH, DEC COUNTER
	BNZ	GOTMOVE		;TEST AGAIN TIL ZERO
;WE HAVE VALID TOP, NOW SAVE IT
	CALL	GETPULSE
	MOVWF	TOPBYTE		; 
	MOVLW	D'180'		;SETS UP FRAME RATE
	PAGE1
	MOVWF	PR2	 	;FOR BOTH PWM SYSTEMS
	PAGE0
	BSF	PORTB,1		;SET BEEP#2
	CALL	PWMSPCL
	CALL	MTRSING		;MAKE MOTOR SING
	MOVLW	0X20		;LOAD COUNTER
	MOVWF	COUNT
DWNSTK	CALL	GETPULSE	;TEST FOR BELOW 1/2 STICK
	CALL 	SETDLY
	MOVLW	D'150'
	SUBWF	TMPCNT,0
	BC	DWNSTK
DWNSTKA	CALL	GETPULSE	;TMPCNT +W HAS DATA
	MOVFW	TMPCNT		;GET DATA
	MOVWF	STROBE		;SAVE IT
	CALL	SETDLY		;CALL FAST DELAY
	CALL	GETPULSE
	MOVFW	TMPCNT 
	SUBWF	STROBE,0	;TEST FOR SAME VALUE?
	BNZ	DWNSTKA		;NO MATCH, DO IT AGAIN
	DECF	COUNT,1		;ITS A MATCH, DEC COUNTER
	BNZ	DWNSTKA		;TEST AGAIN TIL ZERO
;STICK IS AT BOTTOM, NOW STORE IT
DOWNSTP	
	CALL	GETPULSE
	MOVFW	TMPCNT		;GET DATA
	MOVWF	BOTBYTE		;AND STORE IN BOTTOM BYTE
;NOW MOVE DATA INTO BUFFERS
	MOVFW	TOPBYTE
 	MOVFW	BOTBYTE		;GET BOTBYTE
	SUBWF	TOPBYTE,1	;TOPBYTE=DIFFERENCE TOP/BOTBYTE
;NOW SET RATIO CORRECTION
	MOVFW	TOPBYTE		;W NOW HAS POWER RANGE
	MOVWF	MULPLR		;MULTIPLIER HAS COUNT
	MOVLW	0X78		;SET RANGE TO 110
	MOVWF	DIVISOR		;MOVE 43 TO DIVISOR
	CALL	MULTIPLY	;CONVERT TO STANDARD 60 FULL RANGE
	MOVFW	COUNT		;GET RESULT OF CONVERSION
	MOVWF	DIVISOR		;DIVISOR NOW HAS CORRECTIVE VALUE
	MOVLW	0X00		;PRESET PULSE 
	MOVWF	CCPR1L		;KILL MOTOR
	CALL	PWMINIT	
 
	BSF	PULSEHI		;SET CHIP FOR SQUARE WAVE DRIVER
	MOVLW	0X04		;INIT VALUE
	MOVWF	BRAKETM		;INIT BRAKE TIMER VALUE

	MOVLW	D'99'		;SETS UP FRAME RATE
	PAGE1
	MOVWF	PR2	 	;FOR BOTH PWM SYSTEMS
	PAGE0
	BSF	PORTB,2		;SET BEEP#3 
	CALL	PWMSPCL
	CALL	MTRSING		;MAKE MOTOR SING
	CLRF	ERRORLO		;CLEAR ERROR COUNTERS
	CLRF	ERRORHI		;CLEAR ERROR COUNTERS
	MOVLW	0X05		;SET DATA
	MOVWF	ERRORCT		;THIS SLOWS DOWN BINARY OUTPUT FOR SLOW LCD'S
	BSF	ESCARM		;SHOW MOTOR IS ARMED
	BCF	ERROR_1
;NOW WE START RUNNING MOTOR SIGNAL
LOOP3	DECF	ERRORCT,1	;DECREMENT ERROR COUNTER
	BNZ	LOOP3X
	MOVLW	0X05
	MOVWF	ERRORCT		;SET UP COUNTS
	CALL	ERRORPRINT	;SHOW ERRORS
LOOP3X	CALL	GETPULSE	;GET SERVO INPUT

	MOVWF	TEMP		;SAVE IT
 	MOVLW	0X01		;TEST FOR ERROR
 	SUBWF	TEMP,0		;TEST FOR UNDERVALUE
	BZ	ERRORCNT	;ITS ERROR, GO TO ERROR COUNTER
	MOVFW	BOTBYTE		;GET BOTTOM LIMIT
	SUBWF	TEMP,0		;GET DIFFERENCE STORE IN W
	MOVWF	TEMP		;SAVE COPIES IN TEMP
	MOVWF	COUNT	 
	MOVLW	0X03		;GET RID OF 0-3 COUNTS THAT
	SUBWF	TEMP,1		;CRASH IN THE MULTIPLY COMMAND
	BNC	PWROFF		;IF BELOW, GOTO POWER OFF
	BTFSC	TEMP,7		;TEST IF NEGATIVE
	GOTO	PWROFF		;GOTO	POWER OFF
	MOVFW	COUNT		;RESTORE VALUE
	MOVWF	MULPLR		;MOVE TO LOCATION
	CALL	MULTIPLY	;CALL CONVERT
	MOVLW	0X01		;TEST FOR OVER RANGE ON MULT
	XORWF	TEST1,0		;TEST FOR 1
	BZ	ERRORCNT	;ITS ERROR, EXIT	
	MOVFW	COUNT		;GET POWER LEVEL
	ADDLW	D'49'		;45
	MOVWF	TEMP		;SAVE TO TEMP FOR LATER

	MOVLW	D'230'		;SET UP MAX LOOKUP VALUE
	SUBWF	TEMP,0		;TEST FOR OVER LIMITS
	BC	ERRORCNT	;GOTO ERROR ON OVER LIMIT ON TABLE

	MOVFW	TEMP		;RETRIEVE VALUE
	CALL	LOOKUP		;GET GRAPH VALUE
	MOVWF	TEMP		;SAVE LOOKUP VALUE
	MOVLW	0X00 		;TEST FOR ZERO
	XORWF	TEMP,0		;TEST FOR ZERO
	BZ	PWROFF		;GOTO POWER OFF	

	MOVLW	D'250'		;TEST FOR LOOKUP OUT OF RANGE
	XORWF	TEMP,0		;IS IT OVER/UNDER?
	BZ	ERRORCNT

RUNPWM	MOVLW	0X40		;RESET BRAKE COUNTER
	MOVWF	BRAKETM
	BCF	BRAKOUT		;KILL BRAKE 

	CALL	A_DPGM		;CALL ANALOG IN	
	BTFSC	H_BYTE,1	;TEST FOR ABOVE HEX 0200
	GOTO	NORMAL

	MOVLW	0X01		;SET UP LOW TEST
	MOVWF 	H_BYTER		;FOR SUBTRACTION
	MOVLW	0XF8		;SET UP LOW TEST
	MOVWF	L_BYTER		;SET UP LOW TEST
 	CALL	DSUB		;CALL SUBTRACT
	BTFSC	H_BYTER,7	;OVER SETTING?
	GOTO	LEVEL80
 
	MOVLW	0X01		;SET UP LOW TEST
	MOVWF 	H_BYTER		;FOR SUBTRACTION
	MOVLW	0XF0		;SET UP LOW TEST
	MOVWF	L_BYTER		;SET UP LOW TEST
 	CALL	DSUB		;CALL SUBTRACT
	BTFSC	H_BYTER,7	;OVER SETTING?
	GOTO	LEVEL60
 
	MOVLW	0X01		;SET UP LOW TEST
	MOVWF 	H_BYTER		;FOR SUBTRACTION
	MOVLW	0XE8		;SET UP LOW TEST
	MOVWF	L_BYTER		;SET UP LOW TEST
 	CALL	DSUB		;CALL SUBTRACT
	BTFSC	H_BYTER,7	;OVER SETTING?
	GOTO	LEVEL40

  	MOVLW	0X01		;SET UP LOW TEST
	MOVWF 	H_BYTER		;FOR SUBTRACTION
	MOVLW	0XE0		;SET UP LOW TEST
	MOVWF	L_BYTER		;SET UP LOW TEST
 	CALL	DSUB		;CALL SUBTRACT
	BTFSC	H_BYTER,7	;OVER SETTING?
	GOTO	LEVEL20
	CLRF	CCPR1L		;DEAD BATTERY, KILL MOTOR
	GOTO	LOOP3
;BELOW IS LOW BATTERY ROUTINE, LIMITS MAX MOTOR POWER TO 80%, 60%, 40%,20%
LEVEL80	MOVLW	D'80'
	SUBWF	TEMP,0
	BNC	LEVEL60
	MOVLW	D'80'
	MOVWF	CCPR1L		;ELSE LOAD CCPR1L
	GOTO	LOOP3
LEVEL60	MOVLW	D'60'
	SUBWF	TEMP,0
	BNC	LEVEL40
	MOVLW	D'60'
	MOVWF	CCPR1L
	GOTO	LOOP3
LEVEL40	MOVLW	D'40'
	SUBWF	TEMP,0
 	BNC	LEVEL20
	MOVLW	D'40'
	MOVWF	CCPR1L
	GOTO	LOOP3
LEVEL20	MOVLW	D'20'
	SUBWF	TEMP,0
	BNC	LEVELXT
	MOVLW	D'20'
	MOVWF	CCPR1L
	GOTO	LOOP3

LEVELXT	CLRF	CCPR1L
	GOTO	LOOP3

NORMAL	MOVFW	TEMP		;RETRIEVE POWER VALUE
	MOVWF	CCPR1L		;SEND DATA TO PWM REGISTER
	GOTO	LOOP3

;ERROR COUNTING ROUTINE, GOT ERRORS, COUNT THEM 
ERRORCNT
	MOVLW	0X10		;TEST FOR SHORT LOSS OF SIGNAL
	SUBWF	ERRORLO,0	;TEST IT
	BNZ	ERRORX1		;NOT YET
	BSF	ERROR_1		;SET ERROR ON PIN 38	

ERRORX1	MOVLW	D'50'		;TEST FOR SHORT LOSS OF SIGNAL
	SUBWF	ERRORLO,0	;TEST IT
	BNZ	ERRORX2		;NOT YET
	BSF	ERROR_2		;SET ERROR ON PIN 37	

ERRORX2	MOVLW	D'200'		;TEST FOR SHORT LOSS OF SIGNAL
	SUBWF	ERRORLO,0	;TEST IT
	BNZ	ERRORXX		;NOT YET
	BSF	ERROR_3		;SET ERROR ON PIN 36	

ERRORXX	BCF	INPUTOK		;KILL OK OUTPUT
	MOVLW	0XFF		;TEST FOR OUT OF LIMITS
	SUBWF	ERRORHI,0	;IS IT OUT?
	BZ	PWROFF		;
	INCF	ERRORLO,1
	BNZ	PWROFF

	INCF	ERRORHI,1
	CALL	D20MS
	MOVLW	0X00
	MOVWF	CCPR1L
	GOTO	LOOP3
PWROFF 
;ADD BRAKE CIRCUIT HERE
	MOVLW	0X00		;SET CLEAR
	MOVWF	CCPR1L		;VERIFY KILL MOTOR
	MOVF	BRAKETM,0	;TEST GET BRAKE COUNTER
	BZ	SETBRAK		;SET BRAKE
	DECF	BRAKETM,1	;DECREMENT 64x0.05 SEC TIMER
	GOTO	LOOP3		;NO BRAKE, JUST RUN IT
SETBRAK	MOVLW	0X00		;SET CLEAR
	MOVWF	CCPR1L		;VERIFY KILL MOTOR
	BSF	BRAKOUT		;SET BRAKE
	GOTO	LOOP3
	MOVLW	0X00
	MOVWF	CCPR1L
	GOTO	LOOP3

;PULSE WIDTH TIMER, OUTPUT SHOWS PULSE WIDTH IN W AND TMPCNT
GETPULSE			;MUST SET UP FOR NO SIGNAL!
	CLRF	NOSIG1		;CLEAR NO SIGNAL COUNTERS
	MOVLW	0X20		;SET FOR 40 MS TIMEOUT
	MOVWF	NOSIG2
PLOOP3	BTFSS	PULSEIN		;TEST FOR PORT
	GOTO	TIMEOUT		;PORT IS CLEAR, LOOP BACK
	CLRF	TMPCNT		;PORT IS SET, START TIMING
PLOOP4	BTFSS	PULSEIN		;TEST PORT IF CLEAR, GO TO OFF COUNT
	GOTO	PLOOP5   	;SERVO PULSE=0
	INCF	TMPCNT,1
	BZ	PULSENG		;IF COUNT GOES TO ZERO, BAD DATA
	NOP			;TWEEK TIME ADJUSTMENT
	NOP
	NOP
	NOP
	GOTO	PLOOP4		;AND LOOP TIL SERVO=ZERO
PLOOP5 	MOVLW	D'60'
 	SUBWF	TMPCNT,0	;TEST FOR UNDERVALUE
	BNC	PULSENG		;PULSE NO GOOD
	MOVFW	TMPCNT		;SAVE TMPCNT IN W
	BSF	INPUTOK		;SET OK FLAG
	RETURN			;AND RETURN
PULSENG	BCF	INPUTOK		;SHOW LOST SIGNAL
	CLRF	CCPR1L		;KILL PWM AND MOTOR
	BTFSC	PULSEIN		;WAIT TIL PULSE=0 FOR BAD SIGNAL
	GOTO	PULSENG
	CALL	D20MS		;SETDLY FOR A WHILW
	MOVLW	0X01		;OOPS, ERROR FLAG AS 01
	MOVWF	TMPCNT		;SHOW FF FLAG = BAD DATA
	BCF	INPUTOK		;SHOW LOST SIGNAL
	RETURN
TIMEOUT	DECF	NOSIG1,1	;TIMEOUT LOOP1
	BNZ	PLOOP3
	DECF	NOSIG2,1	;TIMEOUT LOOP2
	BNZ	PLOOP3
	GOTO	PULSENG		;EXCEEDED 30 MS, EXIT WITH FF FLAG
;ROUTINE MULTIPLIES BY 100 AND DIVIDES BY ADJUSTMENT FOR CORRECTIONS
;DATA ENTRY, MULCND X MULPLR / DIVISOR = RESULT IN COUNT
MULTIPLY
	CLRF	TEST1			;FROM MPLAB SAMPLE PROGRAMS
	CLRF	H_BYTE
	CLRF	L_BYTE
	MOVLW	8
	MOVWF	COUNT
	MOVLW	0X64		;ENTER DECIMAL 100 INTO MULCND
	MOVWF	MULCND
	MOVF	MULCND,W
	BCF	STATUS,0
MULTX	RRF	MULPLR,1
	BTFSC	STATUS,0
	ADDWF	H_BYTE,1
	RRF	H_BYTE,1
	RRF	L_BYTE,1
	DECFSZ	COUNT,1
	GOTO	MULTX
;H_BYTE+L_BYTE NOW HAS DATA
	MOVFW	DIVISOR
	MOVWF	ACCALO
	CLRF	COUNT
DIVIDE1	INCF	COUNT,1		;DIVIDE COMMAND FROM GENERATOR CHARGER
	BZ	OVERFIL
	MOVFW	ACCALO		;PROGRAM WORKS BY MULTIPLE SUBTRACTIONS
  	SUBWF	L_BYTE,1	;UNTIL H_BYTE GOES TO ZERO
	BNC	DECFILE
	GOTO	DIVIDE1
DECFILE	DECF	H_BYTE,1
	BNZ	DIVIDE1
       	RETURN
OVERFIL	MOVLW	0X01		;COUNTER OVERRANGED
	MOVWF	TEST1 		;RETURN 1 FOR ERROR
	RETURN
;THIS ROUTINE SENDS SERIAL DATA OUT TO THE READER
;INFORMATION IS SENT ERRORLO, ERRORHI, LSD TO MSD
;OVER A PERIOD OF 5.5 MILLISECONDS	
GENPRINT
	MOVFW	TEST1
	MOVWF	SHIFT
	MOVLW	0X08
	MOVWF	SHFTCNT
	CALL	SHFTLOOP
	MOVFW	TEST2
	MOVWF	SHIFT
	MOVLW	0X08
	MOVWF	SHFTCNT
	CALL	SHFTLOOP
	RETURN
ERRORPRINT
	MOVFW	ERRORLO
	MOVWF	SHIFT
	MOVLW	0X08
	MOVWF	SHFTCNT
	CALL	SHFTLOOP
	MOVFW	ERRORHI
	MOVWF	SHIFT
	MOVFW	ERRORHI
	MOVWF	SHIFT
	MOVLW	0X08
	MOVWF	SHFTCNT
	CALL	SHFTLOOP
	RETURN
SHFTLOOP
	CALL	SERIALOUT
	RRF	SHIFT,1
	DECF	SHFTCNT,1
	BNZ	SHFTLOOP
	RETURN

SERIALOUT
	BCF	SERIALD		;CLEAR SERIAL DATA	
	BTFSC	SHIFT,0
	BSF	SERIALD		;SET DATA 
	BSF	SERIALF		;SET READY FLAG
	CALL	D0.1MS
	BCF	SERIALF
	BCF	SERIALD
	CALL	D0.1MS
	CALL	D0.1MS
	RETURN


;SETUP SINGINT MOTOR
MTRSING	BCF 	BRAKOUT		;VERIFY BRAKE IS OFF	
	MOVLW	0X04		;PRESET PULSE 
MTRSIN1	MOVWF	CCPR1L		;KILL MOTOR
	BSF	PULSEHI		;SET CHIP FOR SQUARE WAVE DRIVER
;SHUT OFF MOTOR
	CALL	DELAY
	MOVLW	0X00		;PRESET PULSE 
	MOVWF	CCPR1L		;KILL MOTOR
	RETURN
;ROUTINE INITIALIZES PWM MODE OF PICCHIP
PWMINIT	PAGE1
	MOVLW	D'99'		;SETS UP FRAME RATE
	MOVWF	PR2	 	;FOR BOTH PWM SYSTEMS
PWMSPCL	PAGE0
	CLRF	CCPR1L		;SETS UP PWM1 TO NO SIGNAL
	MOVLW	B'00001100'	;SETS UP PWM FUNCTION
	MOVWF	CCP1CON		;ON PWM1
	MOVLW	B'00001100'
	MOVWF	CCP2CON		;SETS UP PWM2 TO 50%
	MOVLW	D'50'
	MOVWF	CCPR2L

 ;BITS 1-0 CONTROL CLOCK FREQUENCY OF PWM PROGRAM
;00=1:1-10 KHZ, 01=1:4-2.5 KHZ, 1X=1:16-625 KHZ
	MOVLW	B'00000101'	;SETS UP TIMER RATE
 	MOVWF 	T2CON		;AND SEND IT
	RETURN

;1024 STEP AD ROUTINE GETS ANALOG FROM PORT A,0, OUTPUT ON H-L_BYTE
A_DPGM	PAGE1
	BCF	STATUS,RP1
	MOVLW	B'10001110'		;SETUP A/D TO BIT0, ANALOG
	MOVWF	ADCON1			;BIT 4 DIGITAL
	PAGE0

	MOVLW	B'01000001'
	MOVWF	ADCON0
	CALL    FDELAY
	BSF	ADCON0,GO
	CALL	FDELAY
TESTIN	BTFSC	ADCON0,GO
	GOTO	TESTIN
	PAGE1
	MOVFW	ADRESL
	PAGE0
	MOVWF	L_BYTE
	MOVFW	ADRESH
	ANDLW	B'00000011'
	MOVWF	H_BYTE
	RETURN 

;SUBTRACTION, SUBTRACTS INFO WITH CARRY BIT
;LH_BYTE=AD RESULT
;LH_BYTEXY=REF VOLTAGE
DSUB	MOVFW	L_BYTE
	SUBWF	L_BYTER,1
	BNC	DSUB1
	MOVFW	H_BYTE
	SUBWF 	H_BYTER,1
	RETURN
DSUB1	DECF	H_BYTER,1
	MOVFW	H_BYTE
	SUBWF 	H_BYTER,1
	RETURN
;**********************************************************************
;BELOW IS START OF MULTIFUNCTION PROGRAMS
;PROGRAM BELOW INITS LCD DISPLAY AND GENERATES 0.85 TO 2.12 MS SERVO DRIVER
RUNSERVA
	MOVLW	0X01
	MOVWF	FLAG		;SET UP FOR DUAL PULSE
RUNSERV	NOP			;SETUP AND INITIALIZE MASTER CHIP
       	PAGE1      		;SET UP FOR HIGH MEMORY
	MOVLW	B'00000000'	;BITS 4&5 INS, ALL ELSE OUTS
 	MOVWF	TRISC		;BIT C4 IS IN, ALL ELSE OUTS
 	CLRF	TRISB
 	PAGE0			;AND RESET FOR LOW MEMORY 
	CALL	INIT_LCD
 	CALL	CLRDIGT
	MOVLW	0X80
	CALL	ADDRESS
	MOVLW	'P'
	CALL	PRINT
	MOVLW	'u'
	CALL	PRINT
	MOVLW	'l'
	CALL	PRINT
	MOVLW	's'
	CALL	PRINT
	MOVLW	'e'
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT
	
SRVTT
  	CALL	A_DPGM1		;GET ANALOG INPUT DATA
	BCF	STATUS,0	;CLEAR CARRY
	RRF	H_BYTE,1	;DIVIDE BY 8
	RRF	L_BYTE,1
	RRF	H_BYTE,1
	RRF	L_BYTE,1
	MOVLW	0X01
	XORWF	FLAG,0		;TEST FOR DUALS
	BNZ	SLORATE
 
	RRF	H_BYTE,1
	RRF	L_BYTE,1
	MOVLW	D'85'		;LOAD OFFSET VALUE
	ADDWF	L_BYTE,0	;ADD TO POT VALUE, STORE IN W	
SLORAT 	MOVWF	COUNT		;MOVE TO COUNT
	MOVWF	L_BYTE		;SAVE FOR DISPLAY
	INCF	L_BYTE,0	;TWEEK DIGITAL READOUT
	CLRF	H_BYTE		;SAVE FOR DISPLAY
	BSF	PORTC,3		;TURN ON PORT
	CALL	SERVODV		;CALL PRECISION DELAY
	NOP			;ADD TO MAKE 10 US
	NOP
	NOP
	BCF	PORTC,3		;TURN OFF PORT
	CALL	B2_BCD		;CALL DIGIT CONVERT
	MOVLW	0XC0
	CALL	ADDRESS
 
	MOVFW	DIGIT3
	CALL	PRINT
	MOVLW	'.'
	CALL	PRINT
	MOVFW	DIGIT2
	CALL	PRINT
	MOVFW	DIGIT1
	CALL	PRINT


	BSF	PORTC,1		 
	BCF	PORTC,1

	CALL	HD20MSL 	;TEMPORARY FRAME RATE
	GOTO	SRVTT		;TO THIS LOCATION
SLORATE	MOVLW	0X00
	XORWF	L_BYTE,0
	BNZ	SLORAT1
	MOVLW	0X01
	MOVWF	L_BYTE		;MAKE IT NOT ZERO
SLORAT1	MOVFW	L_BYTE		;FOR 1-255 MS PULSE
	MOVWF	COUNT
	GOTO	SLORAT		;FOR DOUBLE PULSE

SERVODV	NOP			;PRECISION 10 US DELAY
	NOP
	NOP
	NOP
	NOP
 	NOP
 	DECF	COUNT,1
	BNZ	SERVODV
	RETURN


;FIRST, LOCATE START OF STROBE PULSES

RUNREAD				;SETUP AND INITIALIZE I/O'S
       	PAGE1      		;SET UP FOR HIGH MEMORY
	MOVLW	B'00110000'	;BITS 4&5 INS, ALL ELSE OUTS
 	MOVWF	TRISC		;BIT C4 IS IN, ALL ELSE OUTS
	CLRF	TRISA
 	CLRF	TRISB
 	PAGE0			;AND RESET FOR LOW MEMORY 


	CALL	INIT_LCD
	CALL	CLRDIGT
	MOVLW	0X80
	CALL	ADDRESS
	MOVLW	'E'
	CALL	PRINT
	MOVLW	'R'
	CALL	PRINT
	MOVLW	'R'
	CALL	PRINT
	MOVLW	'O'
	CALL	PRINT
	MOVLW	'R'
	CALL	PRINT
	MOVLW	'S'
	CALL	PRINT
	CALL	DISPLAY
RUNWW	CALL	STROBE1
	CALL	B2_BCD		;CONVERTS 16 BITS TO 5 BCD'S
	CALL	DISPLAY
	NOP
	GOTO	RUNWW
;ROUTINE RUNS ERROR LOGGING ONLY FROM RECEIVER, AND OUTPUTS TO DATA OUT
ERRORLG	CLRF	ERRORLO
	CLRF	ERRORHI
	PAGE1
	MOVLW	B'00001000'	;BITS 3&4 INS, ALL ELSE OUTS
 	MOVWF	TRISC		;BIT C4 IS IN, ALL ELSE OUTS
	MOVLW	0X06		;SET UP PORT A AS DIGITAL
	MOVWF	ADCON1		;AND SET IT UP
	MOVLW	B'00111111'	;0=ANALOG, 4=PULSE IN
	MOVWF	TRISA
 	CLRF	TRISB
 	PAGE0			;AND RESET FOR LOW MEMORY
 	MOVLW	0x05		;SETUP COUNTER
	MOVWF	ERRORCT
	BSF	ERROR_0		;SET ERROR=ZERO LED ON
ERRORNS	CALL	GETPULSE	;TEST FIRST FOR GOOD SIGNAL
	MOVLW	0X01		;TEST FOR ERROR
	SUBWF	TMPCNT,0	;IS IT ERROR?
	BZ	ERRORNS		;STAY HERE TIL GOOD SIGNAL
ERRORLP	CALL	GETPULSE	
  	MOVLW	0X01		;01=LESS THAN 65MS
	SUBWF	TMPCNT,0	;TEST FOR ERROR
	BZ	ERRORCN		;ERROR, COUNT IT
	MOVLW	D'225'		;OVER 2.45 MS?
	SUBWF	TMPCNT,0
	BNC	ERRORLL

ERRORCN	BCF	INPUTOK		;ERROR, KILL LED
	BCF	ERROR_0		;KILL ERROR LED
	MOVLW	0XFF		;TEST FOR OUT OF LIMITS
	SUBWF	ERRORHI,0	;IS IT OUT?
	BZ	ERRORLL		;
	INCF	ERRORLO,1
	BNZ	ERRORLL
	INCF	ERRORHI,1

ERRORLL	DECF	ERRORCT,1	;DECREMENT COUNTER
	BNZ	ERRORLX
	CALL	ERRORPRINT
	MOVLW	0X05
	MOVWF	ERRORCT
ERRORLX	CALL	D20MS
	GOTO	ERRORLP
;THIS ROUTINE MEASURES RECEIVER PULSE, DISPLAYS ON LCD
PULSEM	
     	PAGE1      		;SET UP FOR HIGH MEMORY
	MOVLW	B'00111111'	;BITS 3&4 INS, ALL ELSE OUTS
 	MOVWF	TRISC		;BIT C4 IS IN, ALL ELSE OUTS
	CLRF	PORTA		;CLEAR OUTPUT LATCHES
	MOVLW	0X01		;SET UP PORT A AS DIGITAL
	MOVWF	ADCON1		;AND SET IT UP
	MOVLW	B'00111111'	;0=ANALOG, 4=PULSE IN
	MOVWF	TRISA
 	CLRF	TRISB
 	PAGE0			;AND RESET FOR LOW MEMORY
	CALL	INIT_LCD	;SHOW COMMANDS ON LCD
	CALL	CLRDIGT
	MOVLW	0X80
	CALL	ADDRESS
	MOVLW	'P'
	CALL	PRINT
	MOVLW	'U'
	CALL	PRINT
	MOVLW	'L'
	CALL	PRINT
	MOVLW	'S'
	CALL	PRINT
	MOVLW	'E'
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT

PULSE0	CLRF	TMPCNT		;CLEAR COUNTER
PULSE1	BTFSC	DATAIN		;JUMP IF DATA INPUT=1
	GOTO	PULSE1
PULSE2	BTFSS	DATAIN		;JUMP IF DATA INPUT=1
	GOTO	PULSE2
PULSE3	INCF	TMPCNT,1		;JUMP IF DATA INPUT=1 AND COUNT
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	BTFSC	DATAIN
	GOTO	PULSE3		
	CLRF	H_BYTE
	MOVFW	TMPCNT
	MOVWF	L_BYTE
	CALL	B2_BCD
	CALL	DISPLYW
	CALL	DELAY
	GOTO	PULSE0
;ROUTINES BELOW CYCLE AND SWEEP SERVO SIGNALS
SERVOCYCLE
   	PAGE1      		;SET UP FOR HIGH MEMORY
	CLRF	TRISB
 	CLRF	TRISC		;BIT C4 IS IN, ALL ELSE OUTS
	PAGE0
	CALL	INIT_LCD
	CALL	A_DPGM1
	MOVFW	H_BYTE
	MOVWF	FLAG		;SAVE FOR RETEST
	MOVLW	B'00000011'
	ANDWF	H_BYTE,1	;CLEAR OUT BYTES
	MOVLW	0X00		;TEST FOR HEX 00
	XORWF	H_BYTE,0	;XOR IT
	BZ	SERVO1X		;AND GOTO RESPECTIVE COMMAND

	MOVLW	0X01
	XORWF	H_BYTE,0
	BZ	SERVO2X

	MOVLW	0X02
	XORWF	H_BYTE,0
	BZ	SERVO3X

	MOVLW	0X03
	XORWF	H_BYTE,0
	GOTO	SERVO4X
;ROUTINE FOLLOWS 'LEFT-CENTER-RIGHT-CENTER-LEFT REPEATEDLY
SERVO1X	MOVLW	80
	CALL	ADDRESS
	MOVLW	'H'
	CALL	PRINT
	MOVLW	'I'
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT
	MOVLW	'L'
	CALL	PRINT
	MOVLW	'O'
	CALL	PRINT
	MOVLW	'W'
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT	
SERVO1	MOVLW	0X01
	MOVWF	DIGIT4		;SET UP VARIABLE DELAY=0
	MOVLW	0X40
	MOVWF	COUNT		;SET UP COUNTER
SERVO1A	CALL	CYCLE
	DECF	COUNT,1
	BNZ	SERVO1A

	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,1		;TEST SAME?
	BZ	SERVO11
	GOTO	SERVOCYCLE

SERVO11	MOVLW	0X7A
	MOVWF	DIGIT4		;SET UP VARIABLE DELAY=0
	MOVLW	0X40
	MOVWF	COUNT		;SET UP COUNTER
SERVO1B	CALL	CYCLE
	DECF	COUNT,1
	BNZ	SERVO1B

	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,1		;TEST SAME?
	BZ	SERVO12
	GOTO	SERVOCYCLE

SERVO12	MOVLW	0XF8
	MOVWF	DIGIT4
	MOVLW	0X40
	MOVWF	COUNT
SERVO1C	CALL	CYCLE
	DECF	COUNT,1
	BNZ	SERVO1C

	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,1		;TEST SAME?
	BZ	SERVO13
	GOTO	SERVOCYCLE

SERVO13	MOVLW	0X07A
	MOVWF	DIGIT4		;SET UP VARIABLE DELAY=0
	MOVLW	0X40
	MOVWF	COUNT		;SET UP COUNTER
SERVO1D	CALL	CYCLE
	DECF	COUNT,1
	BNZ	SERVO1D
	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,1		;TEST SAME?
	BZ	SERVO1
	GOTO	SERVOCYCLE
;SWEEP COMMANDS FOLLOW:
;COUNT=TIME BETWEEN STEPS
;DIGIT4=INPUT FOR D1MSV VARIABLE PULSE
SERVO2X	MOVLW	80
	CALL	ADDRESS
	MOVLW	'R'
	CALL	PRINT
	MOVLW	'A'
	CALL	PRINT
	MOVLW	'M'
	CALL	PRINT
	MOVLW	'P'
	CALL	PRINT
	MOVLW	'F'
	CALL	PRINT
	MOVLW	'A'
	CALL	PRINT
	MOVLW	'S'
	CALL	PRINT
	MOVLW	'T'
	CALL	PRINT	
;FAST SWEEP
SERVO2	MOVLW	0X01
	MOVWF	COUNT		;SET UP STEP RATE
SERVO2A	MOVLW	0X01		;SET UP D1MSV
	MOVWF	DIGIT4		;AND INIT IT
SERVO2B	CALL	CYCLE		;CALL CYCLE
	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,0		;TEST SAME?
	BNZ	SERVOCYCLE
	DECF	COUNT,1
	BNZ	SERVO2B
	MOVLW	0X01
	MOVWF	COUNT
	INCF	DIGIT4,1
	MOVLW	0XF8
	XORWF	DIGIT4,0	;TEST AT TOP?
	BNZ	SERVO2B

SERVO2C	CALL	CYCLE		;CALL CYCLE
	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,0		;TEST SAME?
	BNZ	SERVOCYCLE
	DECF	COUNT,1
	BNZ	SERVO2B
	MOVLW	0X01
	MOVWF	COUNT
	DECF	DIGIT4,1
	MOVLW	0X01
	XORWF	DIGIT4,0	;TEST AT BOTTOM?
	BNZ	SERVO2C
	GOTO	SERVO2
;MEDIUM SWEEP
SERVO3X	MOVLW	80
	CALL	ADDRESS
	MOVLW	'R'
	CALL	PRINT
	MOVLW	'A'
	CALL	PRINT
	MOVLW	'M'
	CALL	PRINT
	MOVLW	'P'
	CALL	PRINT
	MOVLW	'M'
	CALL	PRINT
	MOVLW	'E'
	CALL	PRINT
	MOVLW	'D'
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT		 
SERVO3	MOVLW	0X03
	MOVWF	COUNT		;SET UP STEP RATE
SERVO3A	MOVLW	0X01		;SET UP D1MSV
	MOVWF	DIGIT4		;AND INIT IT
SERVO3B	CALL	CYCLE		;CALL CYCLE
	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,0		;TEST SAME?
	BNZ	SERVOCYCLE
	DECF	COUNT,1
	BNZ	SERVO3B
	MOVLW	0X03
	MOVWF	COUNT
	INCF	DIGIT4,1
	MOVLW	0XF8
	XORWF	DIGIT4,0	;TEST AT TOP?
	BNZ	SERVO3B

SERVO3C	CALL	CYCLE		;CALL CYCLE
	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,0		;TEST SAME?
	BNZ	SERVOCYCLE
	DECF	COUNT,1
	BNZ	SERVO3C
	MOVLW	0X03
	MOVWF	COUNT
	DECF	DIGIT4,1
	MOVLW	0X01
	XORWF	DIGIT4,0	;TEST AT BOTTOM?
	BNZ	SERVO3C
	GOTO	SERVO3
;SLOW SWEEP
SERVO4X	MOVLW	80
	CALL	ADDRESS
	MOVLW	'R'
	CALL	PRINT
	MOVLW	'A'
	CALL	PRINT
	MOVLW	'M'
	CALL	PRINT
	MOVLW	'P'
	CALL	PRINT
	MOVLW	'S'
	CALL	PRINT
	MOVLW	'L'
	CALL	PRINT
	MOVLW	'O'
	CALL	PRINT
	MOVLW	'W'
	CALL	PRINT	
SERVO4	MOVLW	0X0A
	MOVWF	COUNT		;SET UP STEP RATE
SERVO4A	MOVLW	0X01		;SET UP D1MSV
	MOVWF	DIGIT4		;AND INIT IT
SERVO4B	CALL	CYCLE		;CALL CYCLE
	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,0		;TEST SAME?
	BNZ	SERVOCYCLE
	DECF	COUNT,1
	BNZ	SERVO4B
	MOVLW	0X0A
	MOVWF	COUNT
	INCF	DIGIT4,1
	MOVLW	0XF8
	XORWF	DIGIT4,0	;TEST AT TOP?
	BNZ	SERVO4B

SERVO4C	CALL	CYCLE		;CALL CYCLE
	CALL	A_DPGM1		;TEST FOR SAME COMMAND
	MOVLW	B'00000011'
	ANDWF	H_BYTE,0
	XORWF	FLAG,0		;TEST SAME?
	BNZ	SERVOCYCLE
	DECF	COUNT,1
	BNZ	SERVO4C
	MOVLW	0X0A
	MOVWF	COUNT
	DECF	DIGIT4,1
	MOVLW	0X01
	XORWF	DIGIT4,0	;TEST AT BOTTOM?
	BNZ	SERVO4C
	GOTO	SERVO4
 
;THIS ROUTINE CYCLES SERVO, INPUT ON D1MSV IS DIGIT4
CYCLE	BSF	SIGOUT
	CALL	D1MS
	CALL	D1MSV
	BCF	SIGOUT 
	CALL	D20MS
	RETURN


;THIS ROUTINE RUNS VOLTMETER PROGRAM
VOLTMTR PAGE1      		;SET UP FOR HIGH MEMORY
	MOVLW	B'00111111'	;BITS 3&4 INS, ALL ELSE OUTS
 	MOVWF	TRISC		;BIT C4 IS IN, ALL ELSE OUTS
	CLRF	PORTA		;CLEAR OUTPUT LATCHES
	MOVLW	0X01		;SET UP PORT A AS DIGITAL
	MOVWF	ADCON1		;AND SET IT UP
	MOVLW	B'00111111'	;0=ANALOG, 4=PULSE IN
	MOVWF	TRISA
 	CLRF	TRISB
 	PAGE0			;AND RESET FOR LOW MEMORY
	CALL	INIT_LCD
	CALL	CLRDIGT
	MOVLW	0X80
	CALL	ADDRESS
	MOVLW	'V'
	CALL	PRINT
	MOVLW	'O'
	CALL	PRINT
	MOVLW	'L'
	CALL	PRINT
	MOVLW	'T'
	CALL	PRINT
	MOVLW	'S'
	CALL	PRINT
	MOVLW	' '
	CALL	PRINT
	CALL	DISPLAY
VOLTLP	CALL	A_DPGM
	RLF	L_BYTE,1
	RLF	H_BYTE,1

	CALL	B2_BCD		;CONVERTS 16 BITS TO 5 BCD'S
	CALL	DISPLYV
	CALL	DELAY
	GOTO	VOLTLP
;INPUT PULSES FROM SPEED CONTROL MICROCONTROLLER
;	DATAIN		DATA STORED IN H-BYTE AND L_BYTE
;	DATASTB	
STROBE1	MOVLW	0XFF		;INIT COUNTER TIMER
	MOVWF	BCOUNTS
	CLRF	H_BYTE
	CLRF	L_BYTE		;INIT SETTINGS
STROBE2	BTFSC	DATASTB		;TEST STROBE INPUT LO
	GOTO	STROBE2		;IF HI, LOOP AGAIN
	DECF	BCOUNTS,1	;RUN TIMER
	BNZ	STROBE2		;IF NOT END OF STROBES, REPEAT
STROBE3	BTFSS	DATASTB		;WAIT FOR NEXT STROBE
	GOTO	STROBE3
;FOUND FIRST STROBE PULSE AT THIS LOCATION
	MOVLW	0X08
	MOVWF	COUNT
STROBE4	BTFSC	DATAIN		;TEST FIRST DATA
	BSF	L_BYTE,7	;SET L_BYTE IF DATA=1	
	DECF	COUNT,1		;STROBE=1, GO BACK AGAIN
	BZ	STROBEA		;WE ARE DONE, GO TO NEXT
	RRF	L_BYTE,1	;ROTATE TO NEXT
STROBE5	BTFSC	DATASTB		;TEST FOR STROBE=1
	GOTO	STROBE5		;STILL 1, LOOP BACK
STROBE6	BTFSS	DATASTB		;TEST FOR STROBE=0
	GOTO	STROBE6		;STROBE=0 LOOP BACK
	GOTO	STROBE4


STROBEA	BTFSC	DATASTB		;TEST FOR STROBE=1
	GOTO	STROBEA		;STILL 1, LOOP BACK
STROBEB	BTFSS	DATASTB		;TEST FOR STROBE=0
	GOTO	STROBEB		;STROBE=0 LOOP BACK

STROBEY	MOVLW	0X08
	MOVWF	COUNT
STROBE7	BTFSC	DATAIN
	BSF	H_BYTE,7
	DECF	COUNT,1
	BZ	STROBEX
	RRF	H_BYTE,1		;ROTATE TO NEXT
STROBE8	BTFSC	DATASTB
	GOTO	STROBE8
STROBE9	BTFSS	DATASTB
	GOTO	STROBE9
	GOTO	STROBE7

STROBEX	RETURN
;ANALOG DIGITAL CONVERSION FROM PORTA,1
A_DPGM1	PAGE1
	BCF	STATUS,RP1
	MOVLW	B'10000000'
	MOVWF	ADCON1
	PAGE0
	MOVLW	B'01001001'
	MOVWF	ADCON0
	CALL    FDELAY
	BSF	ADCON0,GO
	CALL	FDELAY
TESTIN1	BTFSC	ADCON0,GO
	GOTO	TESTIN1
	PAGE1
	MOVFW	ADRESL
	PAGE0
	MOVWF	L_BYTE
	MOVFW	ADRESH
	ANDLW	B'00000011'
	MOVWF	H_BYTE
	RETURN

DISPLAY	MOVLW	0XC0
	CALL	ADDRESS
	MOVFW	DIGIT5
	CALL	PRINT
	
	MOVFW	DIGIT4
	CALL	PRINT
	
	MOVFW	DIGIT3
	CALL	PRINT
	
	MOVFW	DIGIT2
	CALL	PRINT
	
	MOVFW	DIGIT1
	CALL	PRINT
	RETURN
;DISPLAY 20.46 VOLTS
DISPLYV	MOVLW	0XC0
	CALL	ADDRESS
	MOVFW	DIGIT4
	CALL	PRINT
	
	MOVFW	DIGIT3
	CALL	PRINT
	
	MOVLW	'.'
	CALL	PRINT
	
	MOVFW	DIGIT2
	CALL	PRINT
	
	MOVFW	DIGIT1
	CALL	PRINT
	RETURN


;DISPLAY 20.46 VOLTS
DISPLYW	MOVLW	0XC0
	CALL	ADDRESS
	MOVLW	' '   
	CALL	PRINT
	
	MOVFW	DIGIT3
	CALL	PRINT
	
	MOVLW	'.'
	CALL	PRINT
	
	MOVFW	DIGIT2
	CALL	PRINT

	MOVFW	DIGIT1
	CALL	PRINT

	MOVLW	' '
	CALL	PRINT

	MOVLW	'M'
	CALL	PRINT
	MOVLW	's'
	CALL	PRINT

	RETURN
;INPUT, H_BYTE AND L_BYTE
;OUTPUT, DIGITS4, DIGITS3, DIGITS2, DIGITS1 

B2_BCD	CALL	CLRDIGT
	CALL	BCDCNV
	CALL	ASKBCD
	RETURN  
BCDCNV	BCF     STATUS,0                ; CLEAR THE CARRY BIT
	MOVLW   .16
	MOVWF   BCOUNTS
	CLRF    R0
	CLRF    R1
	CLRF    R2
LOOP16  RLF     L_BYTE, F
	RLF     H_BYTE, F
	RLF     R2, F
	RLF     R1, F
	RLF     R0, F
	DECFSZ  BCOUNTS, F
	GOTO    ADJDEC
	RETLW   0
ADJDEC  MOVLW   R2
	MOVWF   FSR
	CALL    ADJBCD

	MOVLW   R1
	MOVWF   FSR
	CALL    ADJBCD

	MOVLW   R0
	MOVWF   FSR
	CALL    ADJBCD

	GOTO    LOOP16

ADJBCD  MOVLW   3
	ADDWF   0,W
	MOVWF   BTEMP
        BTFSC   BTEMP,3                 ; TEST IF RESULT > 7
	MOVWF   0
	MOVLW   30
	ADDWF   0,W
	MOVWF   BTEMP
        BTFSC   BTEMP,7                 ; TEST IF RESULT > 7
        MOVWF   0                       ; SAVE AS MSD
	RETLW   0
;CONVERSION FROM BCD TO ASKII CODE
ASKBCD  MOVFW	R2
	ANDLW	0X0F
	XORLW	0X30
	MOVWF	DIGIT1

	SWAPF	R2,1
	MOVFW	R2
	ANDLW	0X0F
	XORLW	0X30
	MOVWF	DIGIT2

	MOVFW	R1
	ANDLW	0X0F
	XORLW	0X30
	MOVWF	DIGIT3	
	SWAPF	R1,1
	MOVFW	R1
	ANDLW	0X0F
	XORLW	0X30
	MOVWF	DIGIT4

	MOVFW	R0
	ANDLW	0X0F
	XORLW	0X30
	MOVWF	DIGIT5
	RETURN

PRINTD	MOVWF	PORTB
	CALL	PRINT
	RETURN
CLRDIGT	MOVLW	'0'
	MOVWF	DIGIT1
 	MOVWF	DIGIT2
	MOVWF	DIGIT3
	MOVWF	DIGIT4
	MOVWF	DIGIT5
	RETURN

;INITIALIZATION SEQUENCE
INIT_LCD
        MOVLW   38H                     ;SETUP INITIALIZATION SEQUENCE
	MOVWF	LCDOUT
        BCF     LCDRS                   ;SET R/S TO ZERO
        BSF     LCD_E                   ;AND PULSE CLOCK ON AND OFF
	CALL	DELAYLC
	BCF	LCD_E	
	CALL	DELAYLC

	BSF	LCD_E
	CALL	DELAYLC
	BCF	LCD_E	
	CALL	DELAYLC

	BSF	LCD_E
	CALL	DELAYLC
	BCF	LCD_E	
	CALL	DELAYLC

	BSF	LCD_E
	CALL	DELAYLC
	BCF	LCD_E	
	CALL	DELAYLC

	BSF	LCD_E
	CALL	DELAYLC
	BCF	LCD_E	
	CALL	DELAYLC


        MOVLW   0CH                     ;SET DISPLAY = ON, CURSOR IS OFF
	MOVWF	LCDOUT
	CALL	LSTROBE

        MOVLW   01H                     ;CLEAR DISPLAY AND SET TO HOME
	MOVWF	LCDOUT
	CALL	LSTROBE

        MOVLW   06H                     ;SETS CURSOR TO INCREASE AFTER WRITE
	MOVWF	LCDOUT
	CALL	LSTROBE
	RETURN

ADDRESS
	BSF	LCDRS		;SET R/S TO 5V
	BCF	LCDRS		;SET R/S TO 0V
	MOVWF	PORTB		;MOVE W TO PORT B
	CALL 	LSTROBE		;STROBE IT
	BSF	LCDRS		;SET R/S TO 5V
	RETURN

LSTROBE	BSF	LCD_E		;VERIFY PORT AT ONE
	CALL	FDELY
	BCF	LCD_E  		;SET PORT TO ZERO
	CALL	FDELY
	BSF	LCD_E  		;RETURN TO ONE
	RETURN	
PRINT	MOVWF	PORTB
	CALL	LSTROBE
	RETURN 
;DELAY FOR TRANSMITTER INITIATION
SETDLY	CLRF	DELAY1
SETDLY1	DECF	DELAY1,1
	BNZ	SETDLY1
	RETURN	
;VARIABLE DELAY 0-1 MS ENTER 0 - F8
D1MSV	MOVFW	DIGIT4
	MOVWF	DIGIT3
D1MSV1	DECF	DIGIT3,1
	BNZ	D1MSV1
	RETURN	
;ABOUT 1 MS DELAY
D1MS	MOVLW	0XF8
	MOVWF	DIGIT1
D1MSL	DECF	DIGIT1,1
	BNZ	D1MSL
	RETURN
;ABOUT 20 MS DELAY
D20MS	MOVLW	D'20'
	MOVWF	DIGIT2
D20MSL	CALL	D1MS
	DECF	DIGIT2,1
	BNZ	D20MSL
	RETURN
;ABOUT A 1/2 SECOND DELAY
DELAY	MOVLW	0X03
	MOVWF	DELAY3
	CLRF	DELAY2
DELAYX	CALL	FDELAY	
	DECF	DELAY2,1
	BNZ	DELAYX
	DECF	DELAY3,1
	BNZ	DELAYX	
	RETURN
;ROUTINE IS ABOUT 20 MILLISECONDS   
D18MS	MOVLW	D'05'		;SET UP 20 MS COUNT
	MOVWF	DELAY2
D18MSL	CALL	FDELAY		;CALL 1 MS
	DECF	DELAY2,1	;COUNT IT
	BNZ	D18MSL
	RETURN
;DELAY IS FOR DATA STREAM OUTPUT
D0.1MS	MOVLW	D'20'
	MOVWF	DELAY1
D0.1MSL	DECF	DELAY1,1
	BNZ	D0.1MSL
	RETURN
;JUST A QUICK DELAY ABOUT 1 MS AT 4 Mhz CLOCK
FDELAY	CLRF	DELAY1
FDLY1	DECF	DELAY1,1
	BNZ	FDLY1
	RETURN


FDELY	MOVLW	0X01			;THIS IS A QUICK DELAY
	MOVWF	DELAY2
	CLRF   	DELAY1
DLY1    DECF    DELAY1,1
        BNZ     DLY1
	DECF	DELAY2,1
	BNZ	DLY1
        RETURN
HD20MSL	MOVLW	0X03		;SET UP 20 MS COUNT
	MOVWF	DELAY2
HD20MSX	CALL	FDELAY		;CALL 1 MS
	DECF	DELAY2,1	;COUNT IT
	BNZ	HD20MSX
	RETURN
;DELAY IS FOR DATA STREAM OUTPUT
D0.1MSF	MOVLW	D'20'
	MOVWF	DELAY1
HD0.1MSL
	DECF	DELAY1,1
	BNZ	HD0.1MSL 
	RETURN

DELAYLC	CLRF	DELAY2
	CLRF   	DELAY1
DLY1LC  DECF    DELAY1,1
        BNZ     DLY1
	DECF	DELAY2,1
	BNZ	DLY1LC
        RETURN
	END
vollrathd is online now Find More Posts by vollrathd
Reply With Quote
Old Jul 21, 2015, 10:44 PM
John michel is offline
Find More Posts by John michel
Registered User
Joined Jun 2013
540 Posts
Quote:
Originally Posted by Takao Shimizu View Post
Arduino Brushed DC motor controller, also with reverse

Arduino Sketch's PWM bug report is here
https://github.com/arduino/Arduino/issues/2455

Takao
thanks for this information
John michel is offline Find More Posts by John michel
RCG Plus Member
Old Jul 22, 2015, 09:47 AM
Ron van Sommeren is offline
Find More Posts by Ron van Sommeren
homo ludens modellisticus
Ron van Sommeren's Avatar
Netherlands, GE, Nijmegen
Joined Feb 2001
12,052 Posts
Quote:
Originally Posted by Takao Shimizu View Post
Arduino Brushed DC motor controller, also with reverse ...
Quote:
Originally Posted by vollrathd View Post
... I built up a number of different MicroChip PicChip ESCs that evolved to this project in 2001. ...
Both Takao's and Denny's designs added to opening post.

Vriendelijke groeten Ron
Ron van Sommeren is offline Find More Posts by Ron van Sommeren
Reply With Quote
Old Jul 22, 2015, 08:45 PM
Takao Shimizu is offline
Find More Posts by Takao Shimizu
Registered User
Tokyo, Japan
Joined Nov 2002
903 Posts
8bit Arduino RC Brushed DC motor ESC with reverse + BEC output 1.3A + Programmable Over-current protection + Output OFF user protection when powered + over 60V over-voltage protection + MOSFET driver over heat protection.

This is for 6V under voltage protecion ESC as 2 Li-Po ESC.

Takao
Takao Shimizu is offline Find More Posts by Takao Shimizu
Last edited by Takao Shimizu; Jul 22, 2015 at 10:16 PM.
Reply With Quote


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Is this speed controller ok for a brushed Zoom 400? waynekinney Mini Helis 4 May 13, 2005 01:28 PM
Yippee! Brushless motor with built in logic for driving by brushed controllers! KreAture DIY Electronics 10 Nov 03, 2004 12:42 PM
What controller to buy for brushed motor with LiPos nuevo Power Systems 8 Apr 19, 2004 10:38 PM
WTB brushed controller + gearbox for aveox 1406 aryeh Aircraft - Electric - Airplanes (FS/W) 0 Dec 03, 2002 02:23 AM