Indexer not indexing...a basic PBP problem??


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi jellis00,
    Don't know if this is a problem or not, I have never seen it done this way before:
    Code:
    C1.Byte0 
    C1.Byte1
    I have seen it done this way:
    Code:
    C1.HighByte
    C1.LowByte
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    Jellis

    There seems to be some inconsistency in your code. Before the while, you write 7,i
    In the while, you do i=i+c1 followed by write 8,i The variable i being a word sized entity would write to 8,9. Is this what you're seeing? Location 8 will always read 0 since the high byte of i would be zero (you're counting till 20 only). Other than this, the only reason for not breaking out of the code will be C1 never catches any counts.

    Jerson

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


    Did you find this post helpful? Yes | No

    Default

    Also I don't like the pause 200 inside the loop. Are you sure you are not missing any events there?

    Ioannis

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    Jellis

    There seems to be some inconsistency in your code. Before the while, you write 7,i
    In the while, you do i=i+c1 followed by write 8,i The variable i being a word sized entity would write to 8,9. Is this what you're seeing? Location 8 will always read 0 since the high byte of i would be zero (you're counting till 20 only). Other than this, the only reason for not breaking out of the code will be C1 never catches any counts.

    Jerson
    Hi Jerson,
    So he would need to do write 8,i.HighByte Write 9,i.LowByte ?
    EDIT: thinking about it . . . if he is only counting to 20, why use a word variable at all, should be a byte , Now I get it.
    Last edited by Archangel; - 24th March 2009 at 08:01.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    Hi Joe

    The initial write is to locations 7 and 8. The write inside the while loop is to 8,9. So, the location that I assume he's looking at is 7 this obviously wouldn't change from 0.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    Hi Joe

    The initial write is to locations 7 and 8. The write inside the while loop is to 8,9. So, the location that I assume he's looking at is 7 this obviously wouldn't change from 0.
    Hi Jerson, I get that, if you store your lawnmower in your own garage, looking next door will likely not find it. I am curious though, his statement :
    Code:
    WRITE 5,C1.Byte0 ' Write count into EEPROM location 5,6 for post-run count test
    WRITE 6,C1.Byte1
    is this valid in PBP ? And my second question pertains to his declaring i as WORD, Wouldn't he write it as var.lowbyte ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Thumbs up Indexeer not indexing

    Thanks to the excellent advice from you guys, I modified the code and it now works in the form shown below. Notice I also changed the processing epoch of the COUNT loop and reduced the Pause, because of one of your comments. With this sampling rate of the sensor pulse input rate I shouldn't miss any events. Even if I miss a couple, this resolution will adequately support the application.

    I am also going to continue to use WORD rather than BYTE for the variables since the production version may encounter more than 256 events during the combined epochs.

    When I finally understood from your comments that WRITE was overwriting the EEPROM address that I was using to see if the indexer was indexing with a HighByte that was continuously zero, I was able to solve the problem. Actually, the indexer statement was working....I just couldn't see that it was by the way I was trying to monitor it.
    Can't tell you all enough how much I appreciate your help in resolving this problem! As a long term Visual Basic programmer, my faith in PBP is restored!

    Code:
    'Registers Settings
    TRISA = 0           ' Set PORTA pins to outputs
    TRISB = 0           ' Set all PORTB and PORTC pins to outputs
    TRISC = 0
    ANSEL = 0           ' Set all pins to digital
    ANSELH = 0
    PORTC = 0			' Preset LEDs off
    TRISA.1 =1          ' Set RA1 as input port for meter pulse inputs
    
    'Variables Initialization
     switchstate   var bit ' Stores value of last measured switchstate
     k             CON 60  ' Calibration factor for flow meter...# pulses per gal
     i             VAR WORD    ' Index used in Gallon counter Repeat...Until loop
     C1            VAR WORD    ' Storage variable for count from COUNTER
    
    'Start...normal code here
    MAIN:
          'Send PWM pulse to latching solenoid to open valve
            'Generates 10 millisec pulse on RC3 output pin
             LOW PORTC.3            ' Initialize output pulse polarity
             PULSOUT PORTC.3,1000   ' Generate 10 msec pulse to RC3               
      
        ' Valve should be open at this point and water flowing
                
        ' Start measuring output of flow meter at RA1 input pin
        C1 = 0           ' Initialize pulse count variable to zero
        i = 0            ' Initialize total pulse count index to zero
        REPEAT ' Assume it takes k accumulated pulses for required gallons
            ' Count the number of pulses from Hall Effect Magnetic Sensor in 5 sec
            ' epochs and add count from each epoch to total accumulation and then 
            ' shutoff the valve when count meets i>k criteria.
            Count PORTA.1,5000,C1
            'WRITE 5,C1.HighByte    ' Write count into EEPROM location 5,6 during
            'WRITE 6,C1.LowByte     ' pre-production testing
             'Slowly blink LED during water flow  
               HIGH PORTC.0         ' If we get here, Blink the LED once
               PAUSE 100
               LOW PORTC.0
            i = i + C1              ' Add count to total pulse accumulation indexer
         'When i >= k, required gallons have flowed by the meter
         UNTIL i > k
         'WRITE 7,i.HighByte   'Store result as test of code..not in production
         'Write 8,i.LowByte
         GoTo ShutValve  
    
    ShutValve: 'Send PWM pulse to latching solenoid to close valve
                PULSOUT PORTC.3,1000   ' Generate required 10 msec pulse to RC3
      
        ' Valve should be closed at this point and no water flowing
        
        ' Put code here to test if flow meter has stopped as an indication that
        ' no water is flowing...is a double check on valve closure.
            C1 = 0                 ' Reset pulse counter to zero
            Count PORTA.1,10000,C1 ' Collect meter pulse input, if any, for 10 secs
            IF C1 > 0 Then
                ' Water is still flowing...close the valve!
                PULSOUT PORTC.3,1000   ' Command valve solenoid to close
            ENDIF
     
        ' Put code here to put Microcontroller back to Sleep State to wait for
        ' next Interrupt
            SLEEP = 65,535 
    END

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jellis00 View Post
    Thanks to the excellent advice from you guys, I modified the code and it now works in the form shown below. Notice I also changed the processing epoch of the COUNT loop and reduced the Pause, because of one of your comments. With this sampling rate of the sensor pulse input rate I shouldn't miss any events. Even if I miss a couple, this resolution will adequately support the application.

    I am also going to continue to use WORD rather than BYTE for the variables since the production version may encounter more than 256 events during the combined epochs.

    When I finally understood from your comments that WRITE was overwriting the EEPROM address that I was using to see if the indexer was indexing with a HighByte that was continuously zero, I was able to solve the problem. Actually, the indexer statement was working....I just couldn't see that it was by the way I was trying to monitor it.
    Can't tell you all enough how much I appreciate your help in resolving this problem! As a long term Visual Basic programmer, my faith in PBP is restored!

    Code:
    'Registers Settings
    TRISA = 0           ' Set PORTA pins to outputs
    TRISB = 0           ' Set all PORTB and PORTC pins to outputs
    TRISC = 0
    ANSEL = 0           ' Set all pins to digital
    ANSELH = 0
    PORTC = 0			' Preset LEDs off
    TRISA.1 =1          ' Set RA1 as input port for meter pulse inputs
    
    'Variables Initialization
     switchstate   var bit ' Stores value of last measured switchstate
     k             CON 60  ' Calibration factor for flow meter...# pulses per gal
     i             VAR WORD    ' Index used in Gallon counter Repeat...Until loop
     C1            VAR WORD    ' Storage variable for count from COUNTER
    
    'Start...normal code here
    MAIN:
          'Send PWM pulse to latching solenoid to open valve
            'Generates 10 millisec pulse on RC3 output pin
             LOW PORTC.3            ' Initialize output pulse polarity
             PULSOUT PORTC.3,1000   ' Generate 10 msec pulse to RC3               
      
        ' Valve should be open at this point and water flowing
                
        ' Start measuring output of flow meter at RA1 input pin
        C1 = 0           ' Initialize pulse count variable to zero
        i = 0            ' Initialize total pulse count index to zero
        REPEAT ' Assume it takes k accumulated pulses for required gallons
            ' Count the number of pulses from Hall Effect Magnetic Sensor in 5 sec
            ' epochs and add count from each epoch to total accumulation and then 
            ' shutoff the valve when count meets i>k criteria.
            Count PORTA.1,5000,C1
            'WRITE 5,C1.HighByte    ' Write count into EEPROM location 5,6 during
            'WRITE 6,C1.LowByte     ' pre-production testing
             'Slowly blink LED during water flow  
               HIGH PORTC.0         ' If we get here, Blink the LED once
               PAUSE 100
               LOW PORTC.0
            i = i + C1              ' Add count to total pulse accumulation indexer
         'When i >= k, required gallons have flowed by the meter
         UNTIL i > k
         'WRITE 7,i.HighByte   'Store result as test of code..not in production
         'Write 8,i.LowByte
         GoTo ShutValve  
    
    ShutValve: 'Send PWM pulse to latching solenoid to close valve
                PULSOUT PORTC.3,1000   ' Generate required 10 msec pulse to RC3
      
        ' Valve should be closed at this point and no water flowing
        
        ' Put code here to test if flow meter has stopped as an indication that
        ' no water is flowing...is a double check on valve closure.
            C1 = 0                 ' Reset pulse counter to zero
            Count PORTA.1,10000,C1 ' Collect meter pulse input, if any, for 10 secs
            IF C1 > 0 Then
                ' Water is still flowing...close the valve!
                PULSOUT PORTC.3,1000   ' Command valve solenoid to close
            ENDIF
     
        ' Put code here to put Microcontroller back to Sleep State to wait for
        ' next Interrupt
            SLEEP = 65,535 
    END
    Hi jellis00,
    My question was, . . . actually, answered in this final cut of your code. Thank You
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. PBP 2.60 & ADCON1 problem
    By bitbangerbob in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st October 2009, 12:06
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Big Problem in PBP To receive DMX
    By programmer07 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th March 2007, 18:49
  4. pbp pro versus oshon or bascom basic
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd September 2006, 00:49
  5. Problem DEFINE OSCCAL and PBP 2.46
    By David in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd April 2005, 17:19

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