Menu

Fuzzy logic problem

Help
Mark
2017-12-05
2017-12-06
  • Mark

    Mark - 2017-12-05

    Keep getting errors when trying to determine if the difference between 2 variables is >= or <= then a constant. all variables are byte type.
    Here's the code

    s0 and s1 are from cds sensors being read thru the adc. d1 is the difference between the two sensors. r1 is the constant (10). Depending what the difference is, and if it exceeds the range (constant) determines which routine follows. Thanks

    40: If s0 = s1 Then goto Step2
    41: If s0 > s1 Then
    42: d1 = difference s0 - s1
    43: end if
    44: if d1 >= r1 then goto right
    45: If s0 < s1 then
    46: d1 = difference s1 - s0
    47: end if
    48: If d1 >= r1 then goto Left
    49: goto Step2:

    Here's the errors
    (44): Error: Missing value for parameter SYSINSTRING
    (44): Error: Missing value for parameter SYSCHARCOUNT
    (48): Error: Missing value for parameter SYSINSTRING
    (48): Error: Missing value for parameter SYSCHARCOUNT

     
  • kent_twt4

    kent_twt4 - 2017-12-05

    "difference s1 - s0" is not valid operator or GCB syntax. Cut and paste mistake or maybe that is supposed to be a d1 = s0 - s1 or d1 = s1 - s0?

     
  • Mark

    Mark - 2017-12-05

    The version I'm using is v98.01

    Here's the whole code.

    #chip 16f818, 8
    #config boden = on,
    '
    Dir Portb out                 'set portb to outputs
    Dir Porta in                  'set poeta to inputs
    '
    '
    Dim s0 as byte                'reading from first sensor
    Dim s1 as byte                'reading from second sensor
    Dim d1 as byte                'difference from sensor 1 and 2
    Dim s3 as byte                'reading from third sensor
    Dim s4 as byte                'reading from fourth sensor
    Dim d2 as byte                'difference from sensor 3 and 4
    '
    '
    #define AD_Delay 10ms         'Delay for AD Conversion
    #define use_ad0 true
    #define use_ad1 true
    #define use_ad2 true
    #define use_ad3 true
    #define use_ad4 false
    #define r1
    #define r1 10
    '
    '
    Start:
    s0 = ADRead_porta.0 (an0)      'Read first CdS sensor
    s1 = ADRead_porta.1 (an1)      'Read second CdS sensor
    s3 = ADRead_porta.3 (an2)      'Read third CdS sensor
    s4 = ADRead_porta.4 (an3)      'Read fourth CdS sensor
    goto Step1:
    '
    '
    Step1:
    If s0 = s1 Then goto Step2     'If equal, next step
    If s0 > s1 Then                'If greater, check how much greater
    d1 = difference s0 - s1        'Find the difference
    end if
    if d1 >= r1 then goto right   'Is it within range? If not, go to right
    If s0 < s1 then                'If less, check how much less
    d1 = difference s1 - s0        'Find the difference
    end if
    If d1 >= r1 then goto Left    'Is it within range? If not go to left
    goto Step2:
    '
    '
    Right:                         'Turn the sensor array right
    set portb.7 on                  'Turn on H-bridge
    Wait 100 ms                    'Let it turn for a moment
    set portb.7 off                  'Turn off H-bridge
    goto Step2:                    'Check again
    '
    '
    Left:                          'Turn the sensor array left
    set portb.6 on                  'Turn on H-bridge
    Wait 100 ms                    'Let it turn a moment
    set portb.6 off                  'Turn off H-bridge
    goto Step2:                    'Check again
    '
    '
    Step2:
    if s3 = s4 then goto Start     'If equal, do nothing
    if s3 > s4 then                'If greater, check how much greater
    d2 = difference s3 - s4        'Find the difference
    end if
    if d2 >= r1 then goto Up      'Is it within range? If not, go to up
    if s3 < s4 then                'If less, check how much less
    d2 = difference s4 - s3        'Find the difference
    end if
    if d2 >= r1 then goto Down    'Is it within range? If not go to down
    goto Start:
    '
    '
    Up:                           'Turn the sensor array up
    set portb.5 on                 'Turn on H-bridge
    Wait 100 ms                   'Let it turn a moment
    set portb.5 off                 'Turn off H-bridge
    goto Start:                   'Start again
    '
    '
    Down:                         'Turn the sensor array down
    set portb.4,on                 'Turn on H-bridge
    Wait 100 ms                   'Let it turn a moment
    set portb.4,off                 'Turn off H-bridge
    goto Start:                   'Start again
    End
    '
    
    Here's the errors I'm getting
    
    Solar light tracker.gcb (42): Error: Missing value for parameter SYSINSTRING
    

    (42): Error: Missing value for parameter SYSCHARCOUNT
    (46): Error: Missing value for parameter SYSINSTRING
    (46): Error: Missing value for parameter SYSCHARCOUNT
    (46): Error: Array/Function : has not been declared
    (53): Error: Array/Function : has not been declared
    (53): Error: Missing value for parameter SYSCHARCOUNT

     
  • Hugh Considine

    Hugh Considine - 2017-12-05

    The problem here might be the use of Left and Right as label names. These names are used for string handling functions, and the compiler is thinking that you want to use them.

    Try renaming Left and Right to something else and see if that helps?

     
  • Mark

    Mark - 2017-12-05

    Wow, That did it! Thanks, but now i'm getting this

    Error: GCASM: Symbol ADREAD_PORTA has not been defined
    

    Error: GCASM: Symbol 0(0) has not been defined
    Error: GCASM: Symbol 1(1) has not been defined
    Error: GCASM: Symbol 3(2) has not been defined
    Error: GCASM: Symbol 4(3) has not been defined

     
    • Chris Roper

      Chris Roper - 2017-12-05

      Try:

      Start:
      
          s0 = ADRead(an0)      'Read first CdS sensor
          s1 = ADRead(an1)      'Read second CdS sensor
          s3 = ADRead(an2)      'Read third CdS sensor
          s4 = ADRead(an3)      'Read fourth CdS sensor
      goto Step1:
      

      As per: http://gcbasic.sourceforge.net/help/_readad.html

       
  • Mark

    Mark - 2017-12-05

    Changed that now I get these errors

    (30): Error: Array/Function ADREAD has not been declared
    (30): Error: Invalid variable name: ADREAD(0)
    (31): Error: Array/Function ADREAD has not been declared
    (31): Error: Invalid variable name: ADREAD(1)
    (32): Error: Array/Function ADREAD has not been declared
    (32): Error: Invalid variable name: ADREAD(2)
    (33): Error: Array/Function ADREAD has not been declared
    (33): Error: Invalid variable name: ADREAD(3)

     
    • Chris Roper

      Chris Roper - 2017-12-05

      ADREAD is a new function so I have not personally used it, that is why I
      posted the Link to the HELP Entry.

      You could use ReadAD10(AN0) which is the old command.

      I know that some work has gone into the ADC functions of late so a reread
      of the Help Sections to learn the new features may be in order.

      The Help listing is here: http://gcbasic.sourceforge.net/help/_readad10.html

       
  • Moto Geek

    Moto Geek - 2017-12-05

    @Mark, just scanning your code I noticed you used "difference". This is new to me so I searched the help file and found a command (function) I never knew about. I think you are using it incorrectly based on the help. You have....

    d2 = difference s3 - s4

    but I think it should be...

    d2 = difference (s3, s4)

    This is from the help section...

    Difference

    Syntax:

    Difference ( word_variable1 , word_variable2 ) or
    Difference ( byte_variable1 , byte_variable2 )
    

    Command Availability:

    Available on all microcontrollers.

    Explanation:

    A function that returns the difference between of two numbers. This only supports byte or word variables.

    Example:

    Difference( 8 ,4 ) ' Will return 4
    Difference( 0xff01 , 0xfffa ) ' Will return 0xf9 or 249d
    
     
  • Mark

    Mark - 2017-12-05

    I don't get any errors the way it is, but I did try changing it like you showed, and do get errors. The way you show is more inline with the manual so I'm not sure why. I ended up just changing it to d2 = s3 - s4 and it compiles fine.

    Got the ADRead problem fixed thanks to Kent. Changed it to ReadAD and bingo! No excuse for that sorry.

    Interesting though is now it says "delay units not specified". However if I change
    #define AD_Delay 10ms, to #define AD_Delay 10 ms it works. Neither way really matches the manual.

     
    👍
    1
  • William Roth

    William Roth - 2017-12-05

    The HELP is confusing if not incorrect. In regards to the ReadAD function it states:

        ReadAD
        Syntax:
    
        For a normal ( also called a Single Channel ) read use.
    
            var = ReadAD_port( ANX )
    

    Where does "ReadAD_port" come from? This will not work It should instead read:

     ReadAD
     Syntax:
    
    For a normal (Single Channel ) read use.
    
              user_variable = ReadAD( ANx )
    

    .

    There is no new "ADREAD" function that I am aware of.. Use ReadAD.

     
    • Anobium

      Anobium - 2017-12-05

      Is someone willing to go to GitHub and change this?

       
      • Anobium

        Anobium - 2017-12-06

        Ummmm. I guess that is a no then.

         
  • Moto Geek

    Moto Geek - 2017-12-05

    If you got errors using the "difference" function by how it is shown to use it in the help, then there must be something wrong with that function or the manual. Again, this is a new one to me, and I have never used it, but it should work based on the way it is shown in help, and should have thrown some kind of error the way you were using it, I think...

     
    • Mark

      Mark - 2017-12-05

      The errors I was getting were assiciated with me using "Right" and "Left" as labels. Once I changed that the difference command worked fine. Sorry for the confusion.

      Everything seems to be working just fine now.
      Thanks to everyone for their help and comments.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.