Trying to inch my way to the finish line w/ a 16F1829.........


Closed Thread
Results 1 to 40 of 68

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    So ordinary qudrature encoders then. Are they open collector output? I mean, if they are push-pull type output and you have several connected together there's quite a possibillity one will try to drive the line low while another tries to drive the line high.
    I thought of this when I first got rolling but one of the first things I worked on was to come up with some sort of scope. I made one from some CAT5, a stereo headphone jack from Radio Shack, and some alligator clips to use the mic jack on my laptop. Anyways, I can see the encoder signals, and from day one they have always been super clean. When I combined them I noticed no degradation or conflicts. Right now is probably the dirtiest I've seen because I have 50ft of CAT5 running in my living room window from the dish to my breadboard. (It's HOT in Texas!) But even when I say dirty, they are still really clean square waves, very little edging on the corners, if any, and no misses, dropoffs, or extra trash spikes. Just not PERFECT like you see people playing with PLL's on youtube on $1k scopes.

    Quote Originally Posted by HenrikOlsson View Post
    Another option is to keep a global count for each encoder. Then you have each encoder signal connected to a timer/counter input on the PIC. When you're about to move an axis you clear the timer/counter register and run the motor. The timer/counter register will now track the relative movement which you can add or subtract from your global count for the axis moving.
    timer/counter input?? hmm, I'll have to look into this dark magic you speak of...


    Quote Originally Posted by HenrikOlsson View Post
    You'll still not have the direction information given by the quadrature nature of the encoder but it sounds as if the dish can't be backdriven anyway.
    If by "backdriven", you mean you can't push it by hand and move it, then yes you are right. I think this is why the designers used regular DC motors with gearboxes and encoders instead of say, large steppers. The steppers could have been used with no gears and no encoding, but when powered down, the dish would be flapping in the wind.


    Quote Originally Posted by HenrikOlsson View Post
    When you increase the baudrate each "message" takes less time to send so it's less likely that an interrupt occurs while it's sending.
    Ya but here's the rub... there was no interrupt happening. This has been happening since I put in the interrupt coding, but there was nothing hooked up. The encoder wire was just hanging off the CAT5 while I was jogging the dish manually while physically watching it (to avoid crashing) and tweaking the code for the menus and dish control. And remember, right now, there is no interrupt happening. That was the #2 subject of this post. (Which I still haven't figured out) And the way my code is written,

    Eencoder0Pos = 0
    HIGH UP
    PAUSE 250
    IF Eencoder0Pos = 0 Then goto moveerror

    If I was having a float problem, it would only have to trigger ONE interrupt to avoid my error. My code doesn't require steady movement, or consistent movement, it only requires it not to still be on ZERO, which it is. So with confirmed zero triggered interrupts, it's still dropping characters from the ----- OMFG! Wow it's dark in here! Smells bad too... I just may pull my head out someday! The timer! Duh! I completely forgot the timer interrupt.... I'll get back to ya on this one..... UGH!



    Quote Originally Posted by HenrikOlsson View Post
    If you don't NEED the resolution then increase your count every X interrupt, that would be the easiest.
    That's what I was figuring my factor of 5 on. If I have 250,000 pulses from limit to limit, and I count every 5th pulse, that's now 50,000 which gives me 15000 to spare.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Hi,
    I thought of this when I first got rolling but one of the first things I worked on was to come up with some sort of scope. I made one from some CAT5, a stereo headphone jack from Radio Shack, and some alligator clips to use the mic jack on my laptop. Anyways, I can see the encoder signals, and from day one they have always been super clean. When I combined them I noticed no degradation or conflicts. Right now is probably the dirtiest I've seen because I have 50ft of CAT5 running in my living room window from the dish to my breadboard. (It's HOT in Texas!) But even when I say dirty, they are still really clean square waves, very little edging on the corners, if any, and no misses, dropoffs, or extra trash spikes. Just not PERFECT like you see people playing with PLL's on youtube on $1k scopes
    OK, soundcards generally have a capacitor in series with the input to remove any DC bias, I'm surprised that you get a clean crisp square wave but I guess it depends on at what frequency you measured. What if you remove the encoders and use a switch or whatever to simulate pulses and toggle a LED or something in ISR? That way you should be able to verify if interrupts aren't actually being generated.

    timer/counter input?? hmm, I'll have to look into this dark magic you speak of...
    Your PIC have two timers TMR0 and TMR1. They can be configured as timers or as counters. When configured as counters they will be "clocked" by a signal connected to T0CKI and T1CKI inputs respectively.


    If by "backdriven", you mean you can't push it by hand and move it, then yes you are right. I think this is why the designers used regular DC motors with gearboxes and encoders instead of say, large steppers. The steppers could have been used with no gears and no encoding, but when powered down, the dish would be flapping in the wind.
    That's exactly what I meant. If you don't get the direction information from the quadrature encoders then you must be SURE that each and every pulse from the encoder is caused by the dish moving in the desired direction. If there's any vibration etc it's going to cause "extra" pulses which eventually will cause the position to drift. Sounds like you've got it covered, just something to think about.


    Ya but here's the rub... there was no interrupt happening. (snip) And remember, right now, there is no interrupt happening. That was the #2 subject of this post. (Which I still haven't figured out) And the way my code is written....(snip)....I just may pull my head out someday! The timer! Duh! I completely forgot the timer interrupt.... I'll get back to ya on this one..... UGH!... (snip)
    Ya, exactly...THE TIMER.... :-)

    Lets focus on one issue at the time, pick one and let us know how it goes. We'll go from there!

    /Henrik.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    OK. I got multicalc working.
    I got hserout working.
    hserin - notsomuch.

    My menu looks fine in the terminal. (although I can't test it with interrupts firing since I can't respond and mover the dish) But it just sits there and looks at me stupid when I give a command.

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 6/7/2014                                          *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"
    
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 129 ' 9600 Baud @ 20MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    APFCON0.2 = 1
    APFCON0.7 = 1
    
    
    #CONFIG
        __config _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF &  _CLKOUTEN_OFF & _IESO_OFF
        __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
    #ENDCONFIG
    
    
    DEFINE OSC 20
     
    ANSELA = 0
    ANSELB = 0
    
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _doEncoder,    PBP,  yes
        endm
        INT_CREATE            ; Creates the interrupt processor
    ENDASM
    @   INT_ENABLE   INT_INT
    
    
    LED var PORTC.7
    TRISC.7 = 0
    LED = 0
    DOWN var PORTB.4
    TRISB.4 = 0
    DOWN = 0
    EAST var PORTB.5
    TRISB.5 = 0
    EAST = 0
    WEST var PORTB.6
    TRISB.6 = 0
    WEST = 0
    TRISC.5 = 1
    UP var PORTB.7
    TRISB.7 = 0
    UP = 0
    
    
    
    
    
    
    a0 var byte
    a1 var byte
    e0 var byte
    e1 var byte
    i var byte
    VerboseMode var byte
    cereal var byte
    Aencoder0Pos var word
    Eencoder0Pos var word
    
    
    
    
    
    
    VerboseMode = 1
    
    
    goto MainMenu
    
    
    
    
    doEncoder:
        if UP = 1 then 
            'if e0 = 5 then 
                Eencoder0Pos = Eencoder0Pos + 1
            '    e0 = 0
                if VerboseMode = 1 then Hserout ["Eencoder0Pos = ", #Eencoder0Pos, 13, 10]
            'endif
            'e0 = e0 + 1
        endif
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          if DOWN = 1 then 
            'if e1 = 5 then 
                Eencoder0Pos = Eencoder0Pos - 1
            '    e1 = 0
                if VerboseMode = 1 then Hserout ["Eencoder0Pos = ", #Eencoder0Pos, 13, 10]
            'endif
            'e1 = e1 + 1
        endif
        if EAST = 1 then 
            if a0 = 5 then 
                Aencoder0Pos = Aencoder0Pos + 1
                A0 = 0
                if VerboseMode = 1 then Hserout ["Aencoder0Pos = ", #Aencoder0Pos, 13, 10]
            endif
            a0 = a0 + 1
        endif
        if WEST = 1 then 
            if a1 = 5 then 
                Aencoder0Pos = Aencoder0Pos - 1
                a1 = 0
                if VerboseMode = 1 then Hserout ["Aencoder0Pos = ", #Aencoder0Pos, 13, 10]
            endif
            a1 = a1 + 1
        endif
    @ INT_RETURN
    
    
    
    
    MainMenu:
        gosub CLR
        HSEROUT ["******** MAIN MENU ********", 13, 10, 10]
        HSEROUT [" 1. Start Homing Sequence", 13, 10]
        HSEROUT [" 2. Manual JOG Mode", 13, 10]
        HSEROUT [" 3. Auto-Acquire Satellite", 13, 10]
        HSEROUT [" 4. Stow Dish for Travel", 13, 10, 10]
        HSEROUT ["Enter Your Selection:"]
        hSERIN [cereal]
        if VerboseMode = 1 then HSEROUT [#cereal,13,10]
    '    If cereal = "1" then goto HomeDish 
        If cereal = "2" then goto JogMenu
    '    If cereal = "3" then goto TEST1
    '    If cereal = "4" then goto Startup
    goto MainMenu
    
    
    JogMenu:
        gosub CLR
        pause 250
        HSEROUT ["***** JOG MENU *****", 13, 10, 10]
        HSEROUT ["U - UP", 13, 10]
        HSEROUT ["D - DOWN", 13, 10]
        HSEROUT ["E - EAST", 13, 10]
        HSEROUT ["W - WEST", 13, 10]
        HSEROUT ["S - ALL STOP", 13, 10]
        HSEROUT ["X - MAIN MENU", 13, 10, 10]
        hSERIN [cereal]
        if cereal = "U" Then
            gosub allSTOP
            HIGH UP
        endif
        if cereal = "D" then
            gosub allSTOP
            HIGH DOWN
        endif
        if cereal = "E" then
            gosub allSTOP
            high EAST
        endif
        if cereal = "W" then
            gosub allSTOP
            HIGH WEST
        endif
        if cereal = "S" then gosub allSTOP
        if cereal = "X" then 
            gosub allSTOP
            goto MainMenu
        endif
    goto JOGMenu
    
    
    allSTOP:
        EAST = 0
        UP = 0
        DOWN = 0
        WEST = 0
        if VerboseMode = 1 then GOSUB POS
    return
    
    
    CLR:
        if VerboseMode = 0 then
            For i = 0 to 30
                HSEROUT [10]
            next i
        endif
    return
    
    
    abort:
        gosub allSTOP
        gosub clr
        HSEROUT ["USER STOP! -- MOVE ABORTED!", 13, 10]
        PAUSE(5000)
    goto MainMenu
    
    
    moveerror:
        gosub allSTOP
        gosub clr
        HSEROUT ["SYSTEM ERROR! -- MOVE ABORTED!", 13, 10]
        PAUSE(5000)
    goto MainMenu
    
    
    POS:
        pause 100
        HSEROUT ["  EL -- ", #Eencoder0Pos, "  AZ -- ", #Aencoder0Pos, 13, 10]
        pause 2000
    return

  4. #4
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Are you saying these lines do not execute?

    hSERIN [cereal]
    if VerboseMode = 1 then HSEROUT [#cereal,13,10]

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    • Are you saying these lines do not execute?

      hSERIN [cereal]
      if VerboseMode = 1 then HSEROUT [#cereal,13,10]

      correct


  6. #6
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Quote Originally Posted by thasatelliteguy View Post
    • Are you saying these lines do not execute?

      hSERIN [cereal]
      if VerboseMode = 1 then HSEROUT [#cereal,13,10]

      correct

    HSERIN is not receiving anything then?

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Trying to inch my way to the finish line w/ a 16F1829.........

    Quote Originally Posted by EarlyBird2 View Post
    HSERIN is not receiving anything then?
    that's correct

Similar Threads

  1. Replies: 2
    Last Post: - 31st May 2013, 18:19
  2. line truncate...again
    By queenidog in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th March 2012, 21:58
  3. Most Users Ever On-Line
    By skimask in forum Off Topic
    Replies: 1
    Last Post: - 26th April 2007, 19:06
  4. 2 Line Chars on a 2 Line LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th November 2003, 00:44

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