Problem with 12F629, servo and EEPROM


Results 1 to 14 of 14

Threaded View

  1. #1
    Join Date
    Sep 2006
    Location
    Florida, USA
    Posts
    88

    Default Problem with 12F629, servo and EEPROM

    Hello - I am trying to get this VERY simple program to work, but after hours of banging my head on it, I can't see what I am doing wrong. I'm sure that I will be embarrased when someone points out what I need to do...

    What I want to do is use a 12F629 to drive a servo via a pot. There are 2 pushbuttons to set the minimum and maximum travel limits for the servo and a switch to enable the user to enter the min and max settings. I can drive the servo with the pot without any problem. The problem arises when I try to set the min and max limits. This process consists of switching the Limit Set Enable slide switch to ON, which pulls GPIO.1 high. This tells the PIC to start monitoring the Min and Max pushbuttons. When the user presses one of the buttons, the PIC takes the current position of the servo and stores it in the appropriate variable and then writes the value to internal EEPROM. After setting the Min and Max values and the Limit Set Enable switch is switched off, the servo movement should be limited to between the min and max limits that were just set. Seems simple enough... What is happening when I set a min or max limit is that the servo will not move from that position. For example, I have the total range of movement set from 100 to 250 (1 to 2.5 ms). I get nice movement over this range. If I move the servo to the middle position (let's say 125) and then enable limit setting and then press the Min button, the movement should then be limited to 125 - 250. Well, it acts as though the min and max limits were both set to 125 - the servo won't move from this position. I'm baffled... Another problem that I am having is that the values for the min and max positions are not being written to the internal memory. I do this so that the PIC will remember the last min/max settings. But when I cycle the power, the settings go back to the original min max values (100 & 250). Following is my code and I have attached my circuit. I would appreciate any insight - again, I fully expect to be embarrased....

    @ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; Using Internal Clock, no clock out
    @ DEVICE pic12F629, WDT_ON ; Enable Watch dog timer
    @ DEVICE pic12F629, PWRT_ON ; Enable Power-up timer
    @ DEVICE pic12F629, MCLR_OFF ; Disable MCLR pin
    @ DEVICE pic12F629, BOD_ON ; Enable Brown-out detect
    @ DEVICE pic12F629, CPD_OFF ; EEPROM Protect
    @ DEVICE pic12F629, PROTECT_OFF ; Code Protect off

    TRISIO = %11111110
    INTCON.6=0 ' Disable all unmasked Interrupts
    INTCON.7=0 ' Disable Global Interrupts
    CMCON = 7 ' Disable analog comparator

    ServoOut var GPIO.0
    SetLimitSw var GPIO.1
    PotIn var GPIO.2
    MinSw var GPIO.4
    MaxSw var GPIO.5

    Posit var word
    MinPosit var word
    MaxPosit var word

    'load starting min and max positions at program time
    data @ 0, 0, 100
    data @ 2, 0, 250

    '************************************************* ***************
    low Servoout

    'read in stored min and max limits
    read 0, MinPosit.byte0
    read 1, minposit.byte1
    read 2, MaxPosit.byte0
    read 3, maxposit.byte1

    Start:
    gosub GetServoPosition
    pulsout servoout, posit
    pause 20

    if setlimitsw = 1 then 'check min max buttons
    if minsw = 1 then
    MinPosit = Posit
    write 0, MinPosit.byte0
    write 1, minposit.byte1
    pause 250
    endif

    if maxsw = 1 then
    MaxPosit = Posit
    write 2, MaxPosit.byte0
    write 3, maxposit.byte1
    pause 250
    endif
    endif

    goto start

    '************************************************* ***************
    GetServoPosition:
    high potin
    pause 1
    rctime potin, 1, Posit 'at 4 mhz, returns 0 - 120

    'adjust posit to get values between 75 and 250
    posit = posit + 75 + (posit / 2)

    'now limit posit to 100 - 250 (1 ms - 2.5 ms)
    if posit < 100 then posit = 100
    if posit > 250 then posit = 250

    if setlimitsw = 0 then 'apply limits
    if Posit < MinPosit then Posit = MinPosit
    if Posit > MaxPosit then Posit = MaxPosit
    endif

    return

    '************************************************* ***************

    End
    Attached Images Attached Images

Similar Threads

  1. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  2. Writing to a table.
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th December 2005, 16:20
  3. Servo Recording
    By kenpo in forum General
    Replies: 3
    Last Post: - 2nd September 2005, 16:03

Members who have read this thread : 0

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