View Full Version : Erratic Behavior on a 18F452
markcadcam
- 18th October 2010, 13:38
I am using an 18F452 micro, running at 20 MHz’s. I have four 22k resistors, one each connected in series with pins RA0 thru RA3 with a 5 volt Zener diode clamping the voltage at each of the pins to 5 volts. I am supplying 12 volts to these four 22k resistors from a Hall Effect sensor array under the turret on my lathe. Depending on what position the turret is in will give me 0 or 12 volts on these pins which I use to tell what tool is being used. The problem I’m having is, when I connect these four wires to my circuit board I get erratic behavior on the turret. It loses turret position plus most of the time of I cannot upload the program to the micro using the bootloader. If I unhook these four wires everything is happy again. The only thing I can think of that might be the problem is, maybe there is something else needed to deactivate the analog portion of the micro. I have the line ADCON1 = 7 at the top of my code already. Is there something else I’m missing?
Thanks,
Mark
Acetronics2
- 18th October 2010, 15:00
I am using an 18F452 micro, running at 20 MHz’s. I have four 22k resistors, one each connected in series with pins RA0 thru RA3 ...
Mark
Hi, Mark
provide us a little FULL SCHEME of your thing, plus your DETAILED CONFIG. Header ... ;)
the clearer the scheme, the better the explanations ...
Alain
markcadcam
- 18th October 2010, 16:31
Attached is my code.
'************************************************* ***************
'* Name: HNC Turret Controller.BAS *
'* Started: 11/29/08 *
'* Micro: 18F452 *
'* Updated 10/8/2010 *
'* Serial Input *
'************************************************* ***************
ADCON1 = 7 'set I/O pins to digital on PORT.A
define OSC 20
Include "modedefs.bas"
input PORTA.0
INPUT PORTA.1
INPUT PORTA.2
INPUT PORTA.3
input PORTA.4
INPUT PORTC.2
output PORTD.2
OUTPUT PORTD.3
output PORTD.0
OUTPUT PORTC.3
OUTPUT PORTD.1
B0 var byte
ToolToChangeTo var Byte
Speed var word
StepCount var LONG
HomeSpeed var word
SlowHome var word
i var long 'was WORD
CurrentTool var byte
ToolSlotsToMove var long
RequestedTool var byte
StepsToMove var long
StepsToMoveForEachTool var long ' Steps per tool move
ToolToChangeTo = 0 'zero variable
Speed = 30 ' was 30
StepCount = 0
CurrentTool = 0
StepsToMoveForEachTool = 7500
RequestedTool = 0
StepsToMove = 0
ToolSlotsToMove = 0
i = 0
HomeSpeed = 250
SlowHome = 350
B0 = 0
PORTD.2 = 1
PORTD.1 = 0
PORTD.3 = 0 ' turret cylinder out
Main:
B0 = 0
Serin PORTC.2,T9600,["AB"], # B0
ToolToChangeTo = B0
PORTD.2 = 0 'Pause Deskcnc
DoToolChange:
iF tOOLtOcHANGEtO = 1 tHEN
goto AutoTool1
endif
iF tOOLtOcHANGEtO = 2 tHEN
goto AutoTool2
endif
iF tOOLtOcHANGEtO = 3 tHEN
goto AutoTool3
endif
iF tOOLtOcHANGEtO = 4 tHEN
goto AutoTool4
endif
iF tOOLtOcHANGEtO = 5 tHEN
goto AutoTool5
endif
iF tOOLtOcHANGEtO = 6 tHEN
goto AutoTool6
endif
iF tOOLtOcHANGEtO = 7 tHEN
goto AutoTool7
endif
iF tOOLtOcHANGEtO = 8 tHEN
goto AutoTool8
endif
If ToolToChangeTo = 10 Then ' use tool 10 to home turret
Goto HomeTurret
Endif
AutoTool1: If PORTA.0 = 0 and PORTA.1 = 0 and PORTA.2 = 0 and PORTA.3 = 1 then
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
Else
RequestedTool = 1
Gosub IndexTurret
endif
Repeat
Until PORTA.4 = 0
PORTD.2 = 1 ' UnPause DeskCNC Controller
Goto main
AutoTool2: If PORTA.0 = 0 AND PORTA.1 = 0 AND PORTA.2 = 1 AND PORTA.3 = 0 THEN
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
eLSE
RequestedTool = 2
Gosub IndexTurret
endif
Repeat
Until PORTA.4 = 0
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
AutoTool3: If PORTA.0 = 0 AND PORTA.1 = 0 AND PORTA.2 = 1 AND PORTA.3 = 1 THEN
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
ELSE
RequestedTool = 3
Gosub IndexTurret
endif
Repeat
Until PORTA.4 = 0
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
AutoTool4: If PORTA.0 = 0 AND PORTA.1 = 1 AND PORTA.2 = 0 AND PORTA.3 = 0 THEN
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
ELSE
RequestedTool = 4
Gosub IndexTurret
endif
Repeat
Until PORTA.4 = 0
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
AutoTool5: If PORTA.0 = 0 AND PORTA.1 = 1 AND PORTA.2 = 0 AND PORTA.3 = 1 THEN
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
ELSE
RequestedTool = 5
Gosub IndexTurret
endif
Repeat
Until PORTA.4 = 0
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
AutoTool6: If PORTA.0 = 0 and PORTA.1 = 1 and PORTA.2 = 1 and PORTA.3 = 0 then
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
else
RequestedTool = 6
Gosub IndexTurret
endif
Repeat
Until PORTA.4 = 0
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
AutoTool7: If PORTA.0 = 0 AND PORTA.1 = 1 AND PORTA.2 = 1 AND PORTA.3 = 1 THEN
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
ELSE
RequestedTool = 7
Gosub IndexTurret
endif
Repeat
Until PORTA.4 = 0
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
AutoTool8: If PORTA.0 = 1 AND PORTA.1 = 0 AND PORTA.2 = 0 AND PORTA.3 = 0 THEN
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
ELSE
RequestedTool = 8
Gosub IndexTurret
endif
Repeat
Until PORTA.4 = 0
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
HomeTurret:
High PORTD.1 ' Turn on air valve to lift turret
Repeat
Until PORTA.4 = 1 ' wait for turret to lift and trigger limit switch
pause 500
Repeat ' rotate turret until position tool #1 is reached
high PORTC.3 ' move forward (Direction pin on servo is high)
high PORTD.0
pauseus Homespeed
low PORTD.0
pauseus Homespeed
until PORTA.0 = 0 and PORTA.1 = 0 and PORTA.2 = 0 and PORTA.3 = 1
pause 500
for i = 1 to 5000
low PORTC.3 ' move in reverse to back off of hall effect sensor tool #1
high PORTD.0
pauseus Homespeed
low PORTD.0
pauseus Homespeed
next
Repeat ' rotate turret until position tool #1 hall effect sensor is reached
high PORTC.3 ' move forward
high PORTD.0
pauseus SlowHome
low PORTD.0
pauseus SlowHome
until PORTA.0 = 0 and PORTA.1 = 0 and PORTA.2 = 0 and PORTA.3 = 1
for i = 1 to 5000
low PORTC.3 ' move in reverse to back off of hall effect sensor tool #1
high PORTD.0
pauseus SlowHome
low PORTD.0
pauseus SlowHome
next
for i = 1 to 8800 ' was 8900
high PORTC.3 ' move forward to final position
high PORTD.0
pauseus SlowHome
low PORTD.0
pauseus SlowHome
next
PAUSE 500
HIGH PORTD.3
pause 500
' need some error checking here
LOW PORTD.1 ' Turn off air valve to lower turret
CurrentTool = 1
PAUSE 500
LOW PORTD.3
PORTD.2 = 1 ' UnPause DeskCNC Controller
goto main
IndexTurret:
ToolSlotsToMove = RequestedTool - CurrentTool
if ToolSlotsToMove < 0 then ToolSlotsToMove = ToolSlotsToMove + 8 'only go in one direction
StepsToMove = ToolSlotsToMove * StepsToMoveForEachTool
High PORTD.1 ' Turn on air valve to lift turret
Repeat
Until PORTA.4 = 1
pause 500
for i = 1 To StepsToMove
high PORTC.3 ' move forward
high PORTD.0
pauseus speed
low PORTD.0
pauseus speed
next i
pause 500
HIGH PORTD.3 ' Engage turret locking air cylinder on
PAUSE 500
LOW PORTD.1 ' Turn off air valve to lower turret
pause 500
LOW PORTD.3 ' Disengage turret locking air cylinder off
CurrentTool = RequestedTool
Return
mackrackit
- 18th October 2010, 16:48
http://www.picbasic.co.uk/forum/showthread.php?t=6809&p=42295#post42295
markcadcam
- 18th October 2010, 17:20
Thanks Dave.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.