How to read 4 el.mech.counters?


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Jan 2008
    Posts
    13

    Default How to read 4 el.mech.counters?

    Hello !!!
    I need help. I want to make a interface that will read impulses from 4 electro mechanical counters at once. The counters operate at different speeds and duration. I have solution for 2 counters, but for 4, hm? Please HELP

    Code:
    DEFINE OSC 8
    
    pinin	VAR	PORTC.7		
    pinout	VAR	PORTC.6		
    
    TRISB = 255
    
    B var byte
    
    Serout2 pinout,84,["OK"]
    
    Main:
         B = PORTB
         pause 10
         If PORTB <> 255 then Counter
         goto Main
    
    Counter:
       B = PORTB
       SELECT CASE B
          
          CASE 255
               GOTO MAIN
          CASE 254
               Serout2 pinout,84,["1"]  'counter 1'
               GOTO CEK
          CASE 253
               Serout2 pinout,84,["2"]  'counter 2'
               GOTO CEK1
          CASE 252
               Serout2 pinout,84,["3"]  'counter 1 and counter 2'
               GOTO CEK2
       END SELECT
       
      GOTO Counter
      
    CEK:
      B = PORTB
         SELECT CASE B
          
          CASE 255
               GOTO MAIN
          CASE 253
               Serout2 pinout,84,["2"]
               GOTO CEK1
          CASE 252
               Serout2 pinout,84,["2"] 
               GOTO CEK2
       END SELECT
       
       GOTO CEK
       
    CEK1:
      B = PORTB
         SELECT CASE B
          
          CASE 255
               GOTO MAIN
          CASE 254
               Serout2 pinout,84,["1"]
               GOTO CEK
          CASE 252
               Serout2 pinout,84,["1"] 
               GOTO CEK2
       END SELECT
       
       GOTO CEK1
       
    CEK2:
      B = PORTB
         SELECT CASE B   
          CASE 255
               GOTO MAIN
          CASE 253
              GOTO CEK1
          CASE 254
              GOTO CEK
    
       END SELECT
       
       GOTO CEK2

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Well, I can't offer any suggestions for fixing what you have, other than CTRL-A/DEL.

    Give this a try with HyperTerminal or equivalent @ 19200 baud.
    I'm assuming it's a 16F877.
    Code:
    <font color="#008000"><b>CLEAR                              </b></font><font color="#0000FF"><b><i>' Clear all User RAM
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>OSC </b><font color="#800000"><b>8                       </b></font><font color="#0000FF"><b><i>' change to match your crystal
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>LOADER_USED </b><font color="#800000"><b>1               </b></font><font color="#0000FF"><b><i>' if using a bootloader
    
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>HSER_BAUD </b><font color="#800000"><b>19200             </b></font><font color="#0000FF"><b><i>' Hser baud rate 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>HSER_CLROERR </b><font color="#800000"><b>1              </b></font><font color="#0000FF"><b><i>' Hser clear overflow automatically 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>HSER_RCSTA </b><font color="#800000"><b>90</b></font><b>h              </b><font color="#0000FF"><b><i>' Hser receive status init 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>HSER_TXSTA </b><font color="#800000"><b>24</b></font><b>h              </b><font color="#0000FF"><b><i>' Hser transmit status init 
    
    </i></b></font><b>B        </b><font color="#008000"><b>VAR BYTE
    </b></font><b>LastB    </b><font color="#008000"><b>VAR BYTE                  </b></font><font color="#0000FF"><b><i>' state of pins Last time they changed
    </i></b></font><b>Diff     </b><font color="#008000"><b>VAR BYTE                  </b></font><font color="#0000FF"><b><i>' Difference tween Last and Current bits
    </i></b></font><b>Active   </b><font color="#008000"><b>VAR BYTE                  </b></font><font color="#0000FF"><b><i>' Indicates which inputs are active(LOW)
    </i></b></font><b>Idx      </b><font color="#008000"><b>VAR BYTE                  </b></font><font color="#0000FF"><b><i>' generic loop counter
    </i></b></font><b>Counter  </b><font color="#008000"><b>VAR WORD</b></font>[<font color="#800000"><b>4</b></font>]               <font color="#0000FF"><b><i>' The values of the counters
    
    </i></b></font><b>OPTION_REG</b>.<font color="#800000"><b>7 </b></font>= <font color="#800000"><b>0                   </b></font><font color="#0000FF"><b><i>' enable PORTB pull-ups
    
    ;---[clear screen + display menu]-------------------------------------------
    </i></b></font><b>Refresh</b>:
        <font color="#008000"><b>HSEROUT </b></font>[<font color="#800000"><b>27</b></font>,<font color="#FF0000">&quot;[2J&quot;</font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>, <b>_
                 </b><font color="#FF0000">&quot; A=clear All, (1-4)=Clear Counter#, R=Refresh screen&quot;</font>]
        <font color="#008000"><b>GOTO </b></font><b>DisplayCounters
    
    Main</b>:
        <font color="#0000FF"><b><i>;---[Handle incoming serial data]---------------------------------------
        </i></b></font><font color="#008000"><b>IF </b></font><b>PIR1</b>.<font color="#800000"><b>5 </b></font><font color="#008000"><b>THEN                 </b></font><font color="#0000FF"><b><i>' If serial data has been received
            </i></b></font><font color="#008000"><b>HSERIN </b></font>[<b>Idx</b>]               <font color="#0000FF"><b><i>' get the byte
            </i></b></font><font color="#008000"><b>SELECT CASE </b></font><b>Idx            </b><font color="#0000FF"><b><i>' What did we receive?
              </i></b></font><font color="#008000"><b>CASE </b></font><font color="#FF0000">&quot;A&quot;</font>,<font color="#FF0000">&quot;a&quot;             </font><font color="#0000FF"><b><i>' A - Clear all counters
                  </i></b></font><font color="#008000"><b>FOR </b></font><b>Idx </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>TO </b></font><font color="#800000"><b>3
                    </b></font><b>Counter</b>(<b>Idx</b>) = <font color="#800000"><b>0
                  </b></font><font color="#008000"><b>NEXT </b></font><b>Idx
                  </b><font color="#008000"><b>GOTO </b></font><b>DisplayCounters
              </b><font color="#008000"><b>CASE </b></font><font color="#FF0000">&quot;R&quot;</font>,<font color="#FF0000">&quot;r&quot;             </font><font color="#0000FF"><b><i>' Refresh ANSI Terminal screen
                  </i></b></font><font color="#008000"><b>GOTO </b></font><b>Refresh    
              </b><font color="#008000"><b>CASE </b></font><font color="#FF0000">&quot;1&quot;</font>,<font color="#FF0000">&quot;2&quot;</font>,<font color="#FF0000">&quot;3&quot;</font>,<font color="#FF0000">&quot;4&quot;     </font><font color="#0000FF"><b><i>' numbers clear that counter only
                  </i></b></font><b>Counter</b>(<b>Idx </b>- <font color="#FF0000">&quot;1&quot;</font>) = <font color="#800000"><b>0
                  </b></font><font color="#008000"><b>GOTO </b></font><b>DisplayCounters
              </b><font color="#008000"><b>CASE ELSE
                  HSEROUT </b></font>[<font color="#800000"><b>8</b></font>,<font color="#800000"><b>7</b></font>]         <font color="#0000FF"><b><i>' send backspace + bell
            </i></b></font><font color="#008000"><b>END SELECT
        ENDIF
        </b></font><font color="#0000FF"><b><i>'---[Count Pulses]------------------------------------------------------
        </i></b></font><b>B </b>= <b>PORTB </b>&amp; <font color="#800000"><b>$F0                </b></font><font color="#0000FF"><b><i>' isolate upper 4-bits
        </i></b></font><b>Diff </b>= <b>B </b>^ <b>LastB               </b><font color="#0000FF"><b><i>' see if any of them changed
        </i></b></font><font color="#008000"><b>IF </b></font><b>Diff </b>!= <font color="#800000"><b>0 </b></font><font color="#008000"><b>THEN              </b></font><font color="#0000FF"><b><i>' if any of them changed
            </i></b></font><b>LastB </b>= <b>B
            Active </b>= <b>Diff </b>&amp; ~<b>B         </b><font color="#0000FF"><b><i>' determine which ones are Active
            </i></b></font><font color="#008000"><b>IF </b></font><b>Active </b>!= <font color="#800000"><b>0 </b></font><font color="#008000"><b>THEN
                IF </b></font><b>Active</b>.<font color="#800000"><b>4 </b></font><font color="#008000"><b>THEN </b></font><b>Counter</b>(<font color="#800000"><b>0</b></font>) = <b>Counter</b>(<font color="#800000"><b>0</b></font>) + <font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>' increment actives
                </i></b></font><font color="#008000"><b>IF </b></font><b>Active</b>.<font color="#800000"><b>5 </b></font><font color="#008000"><b>THEN </b></font><b>Counter</b>(<font color="#800000"><b>1</b></font>) = <b>Counter</b>(<font color="#800000"><b>1</b></font>) + <font color="#800000"><b>1
                </b></font><font color="#008000"><b>IF </b></font><b>Active</b>.<font color="#800000"><b>6 </b></font><font color="#008000"><b>THEN </b></font><b>Counter</b>(<font color="#800000"><b>2</b></font>) = <b>Counter</b>(<font color="#800000"><b>2</b></font>) + <font color="#800000"><b>1
                </b></font><font color="#008000"><b>IF </b></font><b>Active</b>.<font color="#800000"><b>7 </b></font><font color="#008000"><b>THEN </b></font><b>Counter</b>(<font color="#800000"><b>3</b></font>) = <b>Counter</b>(<font color="#800000"><b>3</b></font>) + <font color="#800000"><b>1
                </b></font><font color="#008000"><b>GOTO </b></font><b>DisplayCounters
            </b><font color="#008000"><b>ENDIF
        ENDIF
        PAUSE </b></font><font color="#800000"><b>20
    </b></font><font color="#008000"><b>GOTO </b></font><b>Main
    
    </b><font color="#0000FF"><b><i>'--[Display Counter Values]-------------------------------------------------
    </i></b></font><b>DisplayCounters</b>:    
        <font color="#008000"><b>HSEROUT </b></font>[<font color="#800000"><b>27</b></font>,<font color="#FF0000">&quot;[H&quot;</font>]      <font color="#0000FF"><b><i>' home cursor (ANSI)
        </i></b></font><font color="#008000"><b>FOR </b></font><b>Idx </b>= <font color="#800000"><b>0 </b></font><font color="#008000"><b>TO </b></font><font color="#800000"><b>3       </b></font><font color="#0000FF"><b><i>' display all counter values
            </i></b></font><font color="#008000"><b>HSEROUT</b></font>[<font color="#008000"><b>DEC </b></font>(<b>Idx</b>+<font color="#800000"><b>1</b></font>),<font color="#FF0000">&quot;: &quot;</font>,<font color="#008000"><b>DEC5 </b></font><b>Counter</b>(<b>Idx</b>),<font color="#800000"><b>13</b></font>,<font color="#800000"><b>10</b></font>]
        <font color="#008000"><b>NEXT </b></font><b>Idx
        </b><font color="#008000"><b>HSEROUT </b></font>[<font color="#800000"><b>13</b></font>,<font color="#800000"><b>10</b></font>]
    <font color="#008000"><b>GOTO </b></font><b>Main
    </b>
    Cheers,
    DT

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,116


    Did you find this post helpful? Yes | No

    Default

    Nice programming Darrel.

    I was just wondering, are really typing all these control characters < / i >< / b > < / font >< font color="#008000">< b > or is there a trick for this effects?

    Ioannis

  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
    Nov 2003
    Location
    Greece
    Posts
    4,116


    Did you find this post helpful? Yes | No

    Default

    As always there is the obvious in front of us but we try to see further....

    Thanks,
    Ioannis

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by Darrel Taylor View Post
    ;---[clear screen + display menu]-------------------------------------------
    </i></b></font><b>Refresh</b>:
    <font color="#008000"><b>HSEROUT </b></font>[<font color="#800000"><b>27</b></font>,<font color="#FF0000">&quot;[2J&quot;</font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>,<font color="#800000"><b>10</b></font>, <b>_
    </b><font color="#FF0000">&quot; A=clear All, (1-4)=Clear Counter#, R=Refresh screen&quot;</font>]
    <font color="#008000"><b>GOTO </b></font><b>DisplayCounters
    Hi, Darrel

    Could you explain the second Item in the list: "[2J"

    and further

    Code:
    DisplayCounters:    
        HSEROUT [27,"[H"]      ' home cursor (ANSI)
    this one : "[H" ???

    May be simple for you, but unknown for me !!!

    BTW: Thanks for the example ... as I just begin serial comms use to pass parameters to and from my PICs and the PC. ( PC is an horrible black box ... I never look into, as you've understood : LOL )

    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 " !!!
    *****************************************

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,116


    Did you find this post helpful? Yes | No

    Default

    Alain, this is the ANSI escape codes for the terminals. It does exactly what Darrel remarked, Home position in the terminal window.

    Ioannis

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Question

    Hi, Ioannis

    Thanks, but what I do not understand is ... both place cursor @ home position ...

    further question will be :

    is there any table or link to these codes ??? ...

    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 " !!!
    *****************************************

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    Ok Ioannis

    With the right words ... Google is my friend !

    http://ascii-table.com/ansi-escape-sequences.php

    Thanks

    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 " !!!
    *****************************************

Similar Threads

  1. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  2. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  5. How to read data 4 bit
    By chai98a in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th December 2006, 05:07

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