I tested the PIC12F1840 and PIC16F1824 with software serial input. PIC frequency set to 8MHz as required PBP at 9600 baud.
It's working, but the response is kinda slow.
Code:
'* Notes : PIC16F1824 *
'****************************************************************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
#ENDCONFIG
DEFINE OSC 8 ; Use a 8 MHZ internal clock
OSCCON = %01110000
ANSELA = 0
ANSELC = 0
TRISA = %000000
TRISC = %00100001 ; PORT C.5 input RX, C.0 safety, rest output
CM1CON0 = 0 ; Disable comparator 1
CM2CON0 = 0 ; Disable comparator 2
OPTION_REG.7=1 ; Disable weak pull ups
APFCON0.7=0
APFCON0.2=0
; def_ports:
PWPSpin var portc.1 ; servo signal OUTPUT (must be defined before PWPS_Servo.INC)
safety var portc.0 ; safety leash magnetic switch
; def_vars:
n var byte
cmd var byte
; def ext libr:
include "PWPS_Servo.INC" ; Software Servo PWM module
include "modedefs.bas" ; modedefs must be after PWPS_Servo.INC otherwise it doesn't work
init: ; vars start values
position = 1
cmd = 245
n = 0
gosub StartPWPS ; start PWPS module
Main:
Serin2 portc.5,84,20,lost, [wait("Q"),dec cmd] ; wait for Q and then for CMD
if cmd = 155 then ; increment servoimpulse
Position=Position+1
if Position > 1199 then Position = 1200 ; max servoimpulse lenght 2us
gosub SetPWPS
endif
if cmd = 145 then ; decrement servoimpulse
Position=Position-1
if Position < 1 then Position = 1 ; min servoimpulse lenght 1us
gosub SetPWPS
n=n+1 ; long press decrement
if n=255 then ; switch to minimum servoimpulse after cca. 3. sec.
position=1
endif
endif
if cmd = 245 then ; if transmitter is switched OFF servoimpulse to nimimum
Position=1
gosub SetPWPS
endif
if safety = 1 then ; if safety switch is OFF servoimpulse to nimimum
Position=1
gosub SetPWPS
endif
goto main
lost:
n=0 ; clear long press counter value to 0
if safety = 1 then ; if safety switch is OFF servoimpulse to nimimum
Position=1
gosub SetPWPS
endif
goto main
Then I tested even only the PWPS run alone on PIC16F1824 and via serial terminal from PC sent a serial command and the PIC freezes.
Then I tested what if I stop TMR1 (of course PWPS stopped working) but the HW usart works without problems.
Something is wrong with this PWPS include but I can't figure out what.
Bookmarks