PDA

View Full Version : Input problems with 12F629?



achilles03
- 28th June 2005, 04:20
I'm relatively new to PBP, and am still in the learning stages. I'm using a 12F629 to control a servo based on two inputs via pins 1 and 2. Pin 0 is the output pin. For some reason, the 12F629 doesn't recognize any inputs on pins 1 and 2. I've checked to make sure there's no port/pin type conflicts, but I'm sure I'm missing something. Does anyone know what I'm missing?

Thanks in advance,
Dave
(see program below)

-------------------------------------------------
i VAR BYTE

output 0
input 1
input 2

Define OSCCAL_1K 1

low 0

pause 100

loop:
if GPIO.1=1 then turn1
if GPIO.2=1 then turn2
goto loop

turn1:

for i=0 to 5
pulsout 0, 147
pause 20
next i
goto loop

turn2:
for i=0 to 5
pulsout 0, 152
pause 20
next i
goto loop
-------------------------------------------------

mister_e
- 28th June 2005, 04:29
What about

Define OSCCAL_1K 1
CMCON=7 ' disable analog comparator

TRISIO=%11111110 ' set GPIO as output
' others as input
i VAR BYTE

low 0

pause 100

loop:
if GPIO.1=1 then turn1
if GPIO.2=1 then turn2
goto loop

turn1:
for i=0 to 5
pulsout 0, 147
pause 20
next i
goto loop

turn2:
for i=0 to 5
pulsout 0, 152
pause 20
next i
goto loop


Also, make sure you set MCLR pin to +5V OR you disable it at programming time.

Same for internal OSC.

sibujacob
- 9th February 2013, 12:11
hi there

can you tell me from where you got the syntax " PAUSE ..." in your pgm !

I am using C language and dont know such a syntax

AvionicsMaster1
- 9th February 2013, 18:37
Loop is one of those reserved words in PBP3 and I'm pretty sure in earlier versions. It really fouls things up.

If your inputs and outputs are either high or low you want to set all your pins to digital with analog select register. i.e ansel=0. Otherwise the pins get sensed in the middle and often never toggle.

if you want gpio.0 to be low then I think you need low gpio.0 not just low 0.

I've never used PULSOUT before but I'm certain you need to spell out gpio.0 and not just 0

Most people recommend a CLEAR at beginning and a END at end.

I'd also recommend you turn on capitalization of commands in PBP. It helps me recognize some of the reserved words and commands.

If you'll post schematic I'll run it on simulator if you like.



clear
Define OSCCAL_1K 1
CMCON=7 ' disable analog comparator
ansel=0
TRISIO=111110 ' set GPIO as output
' others as input
i VAR BYTE

' commented out low 0
low gpio.0

pause 100

' commented outloop:
main:
if GPIO.1=1 then turn1
if GPIO.2=1 then turn2
' commented out goto loop
goto main

turn1:
for i=0 to 5
' comment out pulsout 0, 147
pulsout gpio.0, 147
pause 20
next i
' commented out goto loop
goto main

turn2:
for i=0 to 5
' comment out pulsout 0, 152
pulsout gpio.0, 152
pause 20
next i
'commented out goto loop
goto main

end

sibujacob
- 10th February 2013, 08:58
thanks avionics master.

Acetronics2
- 10th February 2013, 14:52
This one should work ... ( ISIS tells so ... :rolleyes: )



'************************************************* ***************
'* Name : SERVOTEST0 *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 10/02/2013 *
'* Version : 1.0 *
'* Notes : 12F629 @4 Mhz internal *
'* : *
'************************************************* ***************

#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _CP_OFF & _MCLRE_OFF
#ENDCONFIG

Servo var GPIO.0
Right var GPIO.1
Left var GPIO.2

Define OSCCAL_1K 1
CMCON =7 ' disable analog comparator
' ansel=0 NO ANSEL with the '629 !!!...
TRISIO = %11111110 ' set GPIO as output
' others as input
i VAR BYTE
clear

low Servo
pause 100

' commented outloop:
main:

while 1
IF Right THEN
pulsout Servo, 147
ELSEIF Left THEN
PULSOUT Servo, 152
ELSE
PULSOUT Servo, 150 ' Center/stop ( ? ) if no button pushed ...
ENDIF

Pause 19

WEND

end


Alain

wdmagic
- 10th February 2013, 17:14
you can use Loop in PBP 2.6 and lower, but I agree it should have been a reserved word back then.
I've see some samples of code online that use it. Those sites will need to update their code when 3.0 becomes the standard

AvionicsMaster1
- 11th February 2013, 03:48
Just sayin' according to page 19 of http://ww1.microchip.com/downloads/en/devicedoc/41190c.pdf you need to configure ansel and cmcon to get digital ports. Page 44 tells you how to set up the ANSEL register.

Shouldn't the clear be the first line of the program?

I'd also add a goto main after the WEND or it will only do the movement once.

Just curious, why pause 19? Is that the minimum time for all the stuff to settle out?

grahamg
- 11th February 2013, 05:08
ANSEL and CMCON are only required for a 12f675 that has analog input capability. A12f629 does not have analog inputs so these commands are not required for the 12f629.
The clear command is not required and the variable "I" is also not needed as there are no for/ next loops in the program. A While 1 / wend forms a continuous forever loop so the goto command after the wend is not required. The pause 19 is in the loop so that the pulses are send every 19 milliseconds which is the repeat rate required by the servo decoder.

Acetronics2
- 11th February 2013, 10:23
Hi, Graham

Good !

1) I wanted to wipe line about " I var " ... but timeout for editing post caught me !!! - seriously - that doesn't change anything to the produced Hex , as it's just a compiler directive ...

2) I also wanted to add
LOW Servo just before each PULSOUT Command ... BTW ... could you tell us why ? ;)
to understand the "why" ... just plug and unplug the servo plug for 5 or 6 times in a row ... with power ON

and 3) ... CLEAR might much better be after declaring the variables ... no ???

and ... 4) BINARY numbers must be written %01010101 ... for
TRISIO =

Everything told now ! ;)

Alain

AvionicsMaster1
- 12th February 2013, 14:41
Thanks for straightening me out. You learn something new every day.

n0yox
- 22nd April 2018, 23:05
I have read this thread several times and looked at the datasheet several time as well. I am having problems with code that has worked fine in the past and suddenly I can not make GPIO.0 and GPIO.3 function as inputs. This is the code I have used in the past. I have added a TRISIO statement and this does not seem to help either. “TRISIO = %11001011”
This code works on GPIO.1 but not on GPIO.0 and GPIO.3. I have used three ICs and continue to have no luck?

#IF __PROCESSOR__ = "12F629"
#DEFINE MCU_FOUND 1
#CONFIG
cfg = _INTRC_OSC_NOCLKOUT ; INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN
cfg&= _WDT_ON ; WDT enabled
cfg&= _PWRTE_OFF ; PWRT disabled
cfg&= _MCLRE_OFF ; GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD
cfg&= _BODEN_ON ; BOD enabled
cfg&= _CP_ON ; Program Memory code protection is enabled
cfg&= _CPD_OFF ; Data memory code protection is disabled
__CONFIG cfg
#ENDCONFIG
#ENDIF
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF

CMCON = 7
SYMBOL LTIN = GPIO.0 'input
SYMBOL RTIN = GPIO.1 'input
SYMBOL LTOUT = GPIO.2 'output
SYMBOL FOURIN = GPIO.3 'input
SYMBOL RTOUT = GPIO.4 'output
SYMBOL PEIZO = GPIO.5 'output

Over:
IF LTIN = 1 THEN HIGH PEIZO
IF LTIN = 0 THEN LOW PEIZO
IF RTIN = 1 THEN HIGH PEIZO
IF RTIN = 0 THEN LOW PEIZO
IF FOURIN = 1 THEN HIGH PEIZO
IF FOURIN = 0 THEN LOW PEIZO

GOTO OVER

fratello
- 23rd April 2018, 07:41
See this post : http://www.picbasic.co.uk/forum/showthread.php?t=1426&p=7072#post7072
Maybe is useful !

n0yox
- 24th April 2018, 06:25
I just found my problem. It was these two lines

SYMBOL RTOUT = GPIO.4

SYMBOL PEIZO = GPIO.5

I had changed my board on the last run and forgot to change the pin numbers in the code. The input was working fine it was the output the whole time.My silly mistake:(

SYMBOL RTOUT = GPIO.5

SYMBOL PEIZO = GPIO.4

I am back up and running thank You for your reply!