Erratic Behavior on a 18F452


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29

    Default Erratic Behavior on a 18F452

    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
    Last edited by markcadcam; - 18th October 2010 at 13:50.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by markcadcam View Post
    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Feb 2006
    Location
    Ohio
    Posts
    29


    Did you find this post helpful? Yes | No

    Default

    Thanks Dave.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts