stan cartwright - 2017-04-27

This a demo not a tutorial. Just me experimenting if you like and I thought you might be interested. My main interest is simple robots and modifying a servo is an option to a small geared motor. A servo only needs 1 wire to change direction and speed if it has been modded for contiuous rotation. search modify servo for continuous rotation. A video I did https://youtu.be/aa9sXwqO8GY

;servo modified for continuous rotation demo
#chip 18F25K22, 16
#option explicit
#include <glcd.h>
#config osc=int,WDT=OFF
;
; Define I2C settings - CHANGE PORTS
#define I2C_MODE Master
#define I2C_DATA PORTC.4
#define I2C_CLOCK PORTC.3
#define I2C_DISABLE_INTERRUPTS ON
'Optionally, you can reduce the I2C timings.
#define I2C_BIT_DELAY 0 us
#define I2C_CLOCK_DELAY 0 us
#define I2C_END_DELAY 0 us
; ----- Define GLCD Hardware settings
#define GLCD_TYPE GLCD_TYPE_SSD1306
#define GLCD_I2C_Address 0x78
;
#define analogue_pin porta.1 ;pot wiper
#define servo_pin portb.0 ; Servo signal
dir analogue_pin in
dir servo_pin out
;
dim tmp,servo_position as byte ;pulseout value
;------- set up servo interrupt 50Hz ------
on interrupt timer1overflow Call servo
inittimer1(OSC,PS1_2)
starttimer 1
;------------------------------------------
wait 100 ms
GLCDfntDefaultSize = 3 ;big text on glcd
GLCDCLS
do
servo_position=readad(an1)
;send pot val to servo as pulse width
wait 60 ms ;give time for interrupt to send pulseout and servo to mechanically respond
GLCDPrint (0,0,str(servo_position)+" ")
loop
;;;;;;;;
sub servo ;servo interrupt every 20ms
settimer 1, 25535
pulseout Servo_Pin , servo_position 10us
end sub