Menu

Can't get a simple pin to change state What am I missing?

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

    Mark - 2017-12-05

    It's been a long time since I've done any coding, and you can tell. trying to get a pin to turn on wait for a period of time then turn off. I've been modiying a working program from another basic program, and have worked out most the errors, but this one baffles me for some reason. any help would be appreciated.

    Here's the routine
    52: Up:
    53: set portb.5 on
    54: Wait 100 ms
    55: set portb.5 off
    56: goto Start:

    the error comes when turning off the pin

    Here's the error I get.
    (55): Error: Array/Function : has not been declared

     

    Last edit: Mark 2017-12-05
  • kent_twt4

    kent_twt4 - 2017-12-05

    This code compiles fine, there is no goto label "Start" in the above code.

    #chip 16f877a, 8
    
    
    Up: 'Turn the sensor array up
    Start:    '<======
    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
    

    The problem is probably associated to some other code?

    The standard questions are which compiler version you are using, the device and full code if not too long, or the cut down version that shows the compiler error.

     
  • William Roth

    William Roth - 2017-12-05

    Hi Mark.

    I cannot replicate your error with short bit of code you supplied. Please supply the complete code exactly as it appears in the IDE. And as Kent requested, we need to know what version of GCB you are using.

    The more info you provide the better the help you will receive.

    When posting code to the forum, indent it by 4 spaces and it will be formatted as "code". I ususally indent it 4 spaces in the IDE and then copy and paste in the forum post. If the code really big then include it as an attachment

    William.

     

    Last edit: William Roth 2017-12-05
    • Hugh Considine

      Hugh Considine - 2017-12-05

      Don't forget the other way to format code - use a line of ~ characters before and after the code. Usually three of them is enough (~~~)

       
  • Mark

    Mark - 2017-12-05

    Here's the code. I'm using v.98.01

     #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

    (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

    Edited for code formatting - Removed line numbers -WR

     

    Last edit: William Roth 2017-12-05
  • Mark

    Mark - 2017-12-05

    I just noticed that I posted the code after I took out the led code to work on the another problem i was having. if you look at my first post you can see where the leds were in the code. There was that same led code for each of the labels of up:, down:, left:, and right: different pins for each label but the same error.

     
  • kent_twt4

    kent_twt4 - 2017-12-05

    When I debug with an led I use a wait period after both On and Off.

    By the looks of the code the only time the led would be off for an appreciable time is when both sensors are equal. This equal condition seems very unlikely to happen? would introduce some hysteresis in the form of a band of readings.

    Simplify the problem. Start with only blinking an led with your device. Then move on to reading an ad port, display on terminal screen, etc.

    I am unfamiliar with the AdRead, try like ReadAD(AN0) as in help, when you test this function of GCB.

     
  • Mark

    Mark - 2017-12-05

    Thanks Kent you fixed my "readad" problem. Boy, talk about having dyslexia. I should have known something was wrong when the code helper window didn't pop up.

    The leds should only be on when the motor runs (100ms at a time) you probably wouldn't see much I only added them because I had the extra pins, and thought it would be easy.

     
  • kent_twt4

    kent_twt4 - 2017-12-05

    Sounds like you are starting to get the hang of it, good luck with your solar tracker project. You could also use the comparator module to do that with a little bit of software tweaking, like using with a timeout period.

    Once upon a time I did an analog version of a two axis tracker.

     
  • Mark

    Mark - 2017-12-05

    Thanks again Kent, and to everyone for their help, and comments

    Also now with all the other errors fixed the leds work like a champ

     

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.