Close

Servo test

A project log for nedoPC-16

Computer family on PIC16 microcontrollers

shaosSHAOS 06/04/2018 at 10:490 Comments

Here I use cheap servo MG995 - I'm trying impulses 0.5ms, 1.0ms, 1.5ms, 2.0ms and 2.5ms (last one looks like too long for this servo) with total period of 20ms (and repeat every stage for 50 times to make it 1 second):

On the video you can see nedoCPU-16 board with nedoSerial interface connected to PC through USB-to-Serial adapter (on the left you can see terminal window). Behind there is a lab power supply that shows current and voltage that goes to servo and black power supply on the right gives 13.8V to nedoCPU-16 that has 7805 voltage regulator on-board.

Source code of the test program (here I heavily use macros from shaos-p16.inc and PDBLv1-2A2.inc):

	processor pic16f870
	radix dec
	include "p16f870.inc"
	__CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC
	include "shaos-p16.inc"
	include "PDBLv1-2A2.inc"

temp	equ	0x7E

wait	equ	17

	ORG 0
	goto Start

	ORG 4
	retfie

Start:
	_bank1
	movlw	b'00000000'
	movwf	TRISA^0x80
	_bank0
	_serial_print_ok
	_serial_print_nl
	clrf	PORTA
	_delay_ms 4,0

loop:

	_serial_send_ '0'
	_serial_send_ '.'
	_serial_send_ '5'
	_serial_print_nl
	_movlr 50,temp
loop_0_5:
	_movlr 0x20,PORTA
	_delay_us 500
	_movlr 0x00,PORTA
	_delay_ms 0,2
	_delay_us 500
	_delay_ms 0,wait
	decfsz	temp,f
	goto loop_0_5

	_serial_send_ '1'
	_serial_send_ '.'
	_serial_send_ '0'
	_serial_print_nl
	_movlr 50,temp
loop_1_0:
	_movlr 0x20,PORTA
	_delay_ms 0,1
	_movlr 0x00,PORTA
	_delay_ms 0,2
	_delay_ms 0,wait
	decfsz	temp,f
	goto loop_1_0

	_serial_send_ '1'
	_serial_send_ '.'
	_serial_send_ '5'
	_serial_print_nl
	_movlr 50,temp
loop_1_5:
	_movlr 0x20,PORTA
	_delay_ms 0,1
	_delay_us 500
	_movlr 0x00,PORTA
	_delay_ms 0,1
	_delay_us 500
	_delay_ms 0,wait
	decfsz	temp,f
	goto loop_1_5

	_serial_send_ '2'
	_serial_send_ '.'
	_serial_send_ '0'
	_serial_print_nl
	_movlr 50,temp
loop_2_0:
	_movlr 0x20,PORTA
	_delay_ms 0,2
	_movlr 0x00,PORTA
	_delay_ms 0,1
	_delay_ms 0,wait
	decfsz	temp,f
	goto loop_2_0

	_serial_send_ '2'
	_serial_send_ '.'
	_serial_send_ '5'
	_serial_print_nl
	_movlr 50,temp
loop_2_5:
	_movlr 0x20,PORTA
	_delay_ms 0,2
	_delay_us 500
	_movlr 0x00,PORTA
	_delay_us 500
	_delay_ms 0,wait
	decfsz	temp,f
	goto loop_2_5

	goto loop

	END

 It works stable only if servo and microcontroller use separate power sources (and common ground of course)...

Discussions