Menu

I think I am an idiot, simple code partly works.

Help
Paul Haug
2017-12-08
2017-12-08
  • Paul Haug

    Paul Haug - 2017-12-08

    The following code works showing all 4 bits of port b are working as "Test LED on port B"
    But the sequence of set_taps 1 to 8 (sub set_taps) only displays the first two bytes and the last byte, with bytes 3 to 7 as 0's.
    I have stared at this code for hours but something is wrong with me, or the code.
    Any help would be greatly appreciated.
    ;Simple test for stepper motor application
    ;Dec 7 2017 PEH
    ;Last update:

    ;----- Configuration
    'PicChip Settings.
    #chip 18f27k40, 32
    #config FEXTOSC = OFF, RSTOSC = HFINTOSC_64MHZ, LVP = ON
    #option Explicit
    #config mclr=on ;reset handled internally
    ;----- Constants
    #define delay 500 ms ;Very slow to see steps in LED on port_B
    ;----- Variables
    dim i as byte
    dim j as word ;future use

    ;----- Simple 8 byte Array
    dim xtaps(8) as byte
    xtaps = 0b0001, 0b0010, 0b0011, 0b0100, 0b0101, 0b0110, 0b0111, 0b1111

    ;----- Test Program

    dir PortB out ;only B.0 through B.3 really used for now
    ;
    ;---Test LED on port B ---------------------------------------
    for i = 1 to 15
    portB = i
    wait 200 ms
    next i
    wait 2000 ms 'wait to visualy verify all 4 bits on now
    ;-end of led test-------------
    '

    do
    call set_taps ;temp direct call to taps
    wait 2 s ;just for debug
    loop ;and start over again

    ;----- Subroutines

    sub set_taps ; step thru 8 settings
    for i = 1 to 8
    PortB = xtaps(i)
    wait 500 ms ;for visual led display
    next i
    end sub

     
  • Moto Geek

    Moto Geek - 2017-12-08

    I think you only need...

    set_taps
    

    right after the "do".

    Not

    call set_taps
    

    Not sure if this is THEE problem, but something to look at.

    Edit...

    I think??? that this...

    #config mclr=on ;reset handled internally
    

    should be

    #config mclre=on
    

    missing "e"

    and it could also be "off", not sure what your setup is.

     

    Last edit: Moto Geek 2017-12-08
  • Paul Haug

    Paul Haug - 2017-12-08

    Got it to work but puzzled as to why.
    Changed (dim xtaps(8) as byte) to (dim xtaps(16) as byte)
    Any suggestions as to why this works, there are only 8 bytes of data in the table. ????.
    ;
    **Moto Geek **
    As to call set_taps, using "call" is allowed but not required. I use it to clarify the code for myself. (Old habit)

     

    Last edit: Paul Haug 2017-12-08
  • Moto Geek

    Moto Geek - 2017-12-08

    Ok, didn't know that one, thanks! I wonder why you had to dim xtaps for 16 different bytes instead of 8. I'm puzzled as to why also....

     
  • William Roth

    William Roth - 2017-12-08

    You are not an idiot.

    The compiler is writing the array to a bad memory location. Here are 2 work arounds,
    .

    dim xtaps(16) as byte
    

    .
    .
    This forces the array to a different memory location.
    .

    dim xtaps(8) as byte at 3669
    

    .
    .
    This puts the array at a know good location

    Please test and report results.

    William

     

    Last edit: William Roth 2017-12-08
  • mmotte

    mmotte - 2017-12-08

    Is it true that variables have to be longer than 1 char?

    this line is from the help.:
    "Each variable must be given a name, such as "MyVariable" or "PieCounter". Choosing a name for a variable is easy - just don’t include spaces or any symbols (other than _), and make sure that the name is at least 2 characters (letters and/or numbers) long"

     
    • William Roth

      William Roth - 2017-12-08

      The compiler uses single char variables. Not all of these are in the lexer as Keywords (maybe they should be). While some single char variables wil work others cull cause problems. So it a a good practice to only use variables with 2 or more characters.

       
  • stan cartwright

    stan cartwright - 2017-12-08

    William. "This forces the array to a different memory location."
    Why? The 18f27k40 has 3728 bytes ram. Is the gcb default array allocation taken?

     
    • Anobium

      Anobium - 2017-12-08

      @Stan. Why oh why?

      Bill wrote

      The compiler is writing the array to a bad memory location. Here are 2 work arounds,

      There is no default array allocation - the compiler is not doing what it is expected to do. We are investigating why and it would be wrong to guess the root cause of the issue.

       
  • Paul Haug

    Paul Haug - 2017-12-08

    I did change to dim xtaps(16) and it works, but since this appears as some sort of starnge error/function in the compiler, I switched to a table lookup method, less confusing for me since I have used it previously.

     

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.