Thanks LinkMtech and eggman (sounds like a TV show in the making!). I'll try your comments today.
Happy new year to both of you.
John.
Thanks LinkMtech and eggman (sounds like a TV show in the making!). I'll try your comments today.
Happy new year to both of you.
John.
OK, anthor problem...
I'm trying to run an RC servo from a PIC12F683. I'm using pin 0 as output and pin 1 as input (from receiver)
As long as there is a signal from pin 1, the PULSOUT will output the PULSIN value. When no signal is present (PULSIN=0) then PULSOUT should go to a failsafe value.
Situation: When the signal is present, the PULSOUT sends the PULSIN value, but when PULSIN = 0, the PULSOUT does send the proper value, but in 1/2 second intervals (it pulses the value about every 0.5 sec). I can't figure out why!!!
here's the code:
oSCCON = %01100000 ' Ocs set to 4 MHz
TRISIO = %00000000 ' Set all ports to outputs, in this example
CMCON0 = 7 ' Analog comparators off
ANSEL = 0 ' Analog select set to digital, pg 69 data
ADCON0 = 0 ' A/D turned OFF, pg 68 of data
cont var word
failsafe var word
posoutput var word
posinput var word
usefailsafe var byte
pausetime var word
low gpio.0
low gpio.1
low gpio.2
low gpio.3
failsafe=80
pausetime=10
START:
;pulsout portb.4, failsafe
;pause 50
;goto start
GETSIGNAL:
pulsin gpio.1,1,posoutput
if posoutput=0 then goto runfailsafe
goto runnormal
runfailsafe:
pulsout gpio.0, failsafe
pause pausetime
goto getsignal
runnormal:
pulsout gpio.0, posoutput
pause pausetime
goto getsignal
I have one more...
I want to write the PULSIN value to the memory on the 12F683 (and have it stored even when the power is off) and recall it in the event there is no PULSIN signal.
What are the proper commands to do this?
(I assume write and read)
I.e.
WRITE 5, failsafe
READ 5, failsafe
...but first I have to get the servo thing working!!
This may help with your data storage.
The below code is for a counter, sort of like an odometer. It saves the value to EEPROM at each hit of a switch. When the device is turned on the EEPROM is read and the values placed back into a variable for continued use. Also has the ability to reset the stored values back to zero at start up.
Pick through it and see if it helps.
Code:'* Notes :16F877A '* SAVE TO EEPROM '**************************************************************** '_config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF &_BODEN_OFF DEFINE OSC 20 DEFINE LCD_DREG PORTB define LCD_DBIT 4 DEFINE LCD_RSREG PORTB DEFINE LCD_RSBIT 1 DEFINE LCD_EREG PORTB DEFINE LCD_EBIT 0 DEFINE LCD_BITS 4 DEFINE LCD_LINES 2 DEFINE LCD_COMMANDUS 2000 DEFINE LCD_DATAUS 50 TRISA = %00000000 ADCON1=14 Asm ERRORLEVEL -306 Endasm include "modedefs.bas" 'TOTAL VARS O VAR BYTE 'ONES T VAR BYTE 'TENS H VAR BYTE 'HUNDREDS TH VAR BYTE 'THOUSANDS TTH VAR BYTE 'TEN THOUSANDS HTH VAR BYTE 'HUNDRED THOUSANDS M VAR BYTE 'MILLIONS OD VAR BYTE 'ONES TD VAR BYTE 'TENS HD VAR BYTE 'HUNDREDS THD VAR BYTE 'THOUSANDS TTHD VAR BYTE 'TEN THOUSANDS HTHD VAR BYTE 'HUNDRED THOUSANDS MD VAR BYTE 'MILLIONS 'TOTAL LOGS O_LOG VAR BYTE 'ONES T_LOG VAR BYTE 'TENS H_LOG VAR BYTE 'HUNDREDS TH_LOG VAR BYTE 'THOUSANDS TTH_LOG VAR BYTE 'TEN THOUSANDS HTH_LOG VAR BYTE 'HUNDRED THOUSANDS M_LOG VAR BYTE 'MILLIONS 'READ LOGS READ O_LOG, OD READ T_LOG, TD READ H_LOG, HD READ TH_LOG, THD READ TTH_LOG, TTHD READ HTH_LOG, HTHD READ M_LOG, MD NUM VAR BYTE NUM = 0 pause 1000 CHECK: IF PORTE.2 = 1 THEN GOSUB CL_LOG 'FOR RESET AT START UP IF PORTE.2 = 0 THEN START GOTO CHECK START: HIGH PORTD.2 'LED PAUSE 5 IF PORTD.3 = 1 THEN GOSUB C_P_T 'SWITCH FOR PARTS LOW PORTD.2 PAUSE 5 GOTO START C_P_T: LCDOUT $FE,1,"C TEST" LCDOUT $FE,$C0,DEC MD,DEC HTHD,DEC TTHD,DEC THD,DEC HD,DEC TD,DEC OD O = O + 1 IF O = 10 THEN O = 1 T = T + 1 IF T = 10 THEN T = 0 H = H + 1 IF H = 10 THEN H = 0 TH = TH + 1 IF TH = 10 THEN TH = 0 TTH = TTH + 1 IF TTH = 10 THEN TTH = 0 HTH = HTH +1 IF HTH = 10 THEN HTH = 0 M = M +1 ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF WRITE O_LOG, O WRITE T_LOG, T WRITE H_LOG, H WRITE TH_LOG, TH WRITE TTH_LOG, TTH WRITE HTH_LOG, HTH WRITE M_LOG, M READ O_LOG, OD READ T_LOG, TD READ H_LOG, HD READ TH_LOG, THD READ TTH_LOG, TTHD READ HTH_LOG, HTHD READ M_LOG, MD RETURN CL_LOG: HIGH PORTD.2 PAUSE 100 LOW PORTD.2 PAUSE 100 O = $0 T = $0 H = $0 TH = $0 TTH = $0 HTH = $0 M = $0 WRITE O_LOG, O READ O_LOG, OD WRITE T_LOG, T READ T_LOG, TD WRITE H_LOG, H READ H_LOG, HD WRITE TH_LOG, TH READ TH_LOG, THD WRITE TTH_LOG, TTH READ TTH_LOG, TTHD WRITE HTH_LOG, HTH READ HTH_LOG, HTHD WRITE M_LOG, M READ M_LOG, MD RETURN END
Dave
Always wear safety glasses while programming.
I found that PULSIN will time out while you're waiting for something to happen then was clued in on WHILE:WEND.
So try this command set with something like:
It comes in handy for something like this.Code:WHILE GPIO.1 = 0 ' Repeat this loop while there is no signal pulsout gpio.0, failsafe pause pausetime WEND
Louie
Thanks LinkMTech and Mackrackit:
Both worked. FYI, I fly RC planes and have recently gained interest in the PIC stuff, mostly with the 12F683 due to its size. I'm learning this stuff...slowly (but wow, has it got potential!).
I have a couple more questions hopefully you can help me with.
1. having some issues simply running LED's on ports other than gpio.0 and 1. I'm not sure if I need to assign them, change them??? When trying, I see they have a faint glow???
2. When using GPIO.4 and an input to store a pulsin value, the program works, but if I use GPIO.3 it doesn't. I can't figure that one out.
Thanks again gents.
John.
Bookmarks