Word array behaving like byte array.... wierd


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    forgie's Avatar
    forgie Guest

    Question Word array behaving like byte array.... wierd

    Hi there,
    I have a piece of code which looks like thus:
    <code>
    Sample_Buffer[Sample_Index] = ADC_Buffer
    </code>


    All of these variables are declared as variables. When I check the data, Sample_Buffer[Sample_Index] is always less then 256, although I know that the data in ADC_Buffer is often higher then this.

    I have tested it by changing the code to this:

    <code>
    if ADC_Buffer > 255 then
    lcdout cmd, cls, "BIG NUM"
    endif
    sample_buffer[sample_index] = adc_buffer
    </code>

    And sure, enough, "BIG NUM" is spat out on the LCD. If I use the same check for the Array Variable after copying the data into the array, it always comes back as being < 256.

    Where is the other half of my word going??? Has anyone else seen similar behaviour? Am I doing something really stupid?

    EDIT: This is on an 18f452, using PBP 2.43
    Last edited by forgie; - 31st July 2005 at 15:33.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    We assume that...

    ADC_Buffer has been defined as a WORD variable

    and that...

    Sample_Buffer has been defined correctly as a WORD ARRAY

  3. #3
    forgie's Avatar
    forgie Guest


    Did you find this post helpful? Yes | No

    Default

    <code>
    Sample_Buffer var word[n_samples] 'Array to store samples in
    Sample_Index var word
    ADC_Buffer var word 'Return value for ADC_Reading
    </code>

    This is copied straight from my sourcecode....

  4. #4
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by forgie
    This is copied straight from my sourcecode....
    Code:
    	Sample_Buffer	var word[n_samples]
    Are you really using a variable (n_samples) to specify the size of the array?
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  5. #5
    forgie's Avatar
    forgie Guest


    Did you find this post helpful? Yes | No

    Default Nope, thats a constant....

    Lol I don't think PBP would compile if it were a VAR... nope, it's a constant and it's equal to 300.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    See if this works. If not, it might be due to your older version of PBP. I know
    they've made a few changes/fixes for the 18F series since v2.43.

    Tested with PIC18F452 PBP v2.46:
    Code:
    ' Lab-X1 LCD definitions
    Define  LCD_DREG        PORTD
    Define  LCD_DBIT        4
    Define  LCD_RSREG       PORTE
    Define  LCD_RSBIT       0
    Define  LCD_EREG        PORTE
    Define  LCD_EBIT        1
    Define  LCD_COMMANDUS   2000
    Define  LCD_DATAUS      50
    
    n_samples CON 300
    Sample_Buffer var word[n_samples] 'Array to store samples in
    Sample_Index var word
    ADC_Buffer var word 'Return value for ADC_Reading
    
    CLEAR
    ADCON1 = 7      ' Set PORTA and PORTE to digital
    ADC_Buffer = 1200
    PAUSE 1000
    lcdout $fe,1     ' Cls  Clear LCD screen
    
    Main:
         FOR Sample_Index = 0 to 299
           Sample_Buffer[Sample_Index] = ADC_Buffer
           ADC_Buffer = ADC_Buffer + 100
           LCDOUT "Sample: ",DEC Sample_Index," = ",DEC Sample_Buffer[Sample_Index]
           PAUSE 2000
           LCDOUT $fe,1     ' Cls  Clear LCD screen
        NEXT Sample_Index
        GOTO Main
        
        end
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by forgie
    Lol I don't think PBP would compile if it were a VAR... nope, it's a constant and it's equal to 300.
    you said:
    This is copied straight from my sourcecode....
    and there was no
    Code:
    n_samples CON 300
    ROFL
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th July 2008, 23:19
  3. byte compression
    By Norbert in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th June 2007, 18:04
  4. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 15:23
  5. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 11:47

Members who have read this thread : 1

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