Cread Word unexpected results


Today 20:07
Forum: Absolute Beginners Section
Starter: amod
Views: 0
Replies: 60
+ Reply to Thread
Results 1 to 6 of 6

Thread: Cread Word unexpected results156 days old

  1. #1
    Junior Member mjturner's Avatar
    Join Date
    Dec 2003
    Posts
    88
    Thumbs Up
    Received: 14
    Given: 4
    Total Downloaded
    544.85 MB

    0 Not allowed!

    Default Cread Word unexpected results

    I'm trying to use the CRead command, but getting some odd results on an Enhanced 14bit core.

    Below is the data I'm expecting (Data line), and the data I'm getting (Read line).

    Data: 0000,0000,3180,28B8,3181,295A,01AF,01B0,01B1,01B1
    Read: 0000,0000,3880,01B8,1A81,2F5A,30AF,31B0,31B1,25B1


    I'm reading the data in to a WORD variable.
    Code:
      Dim TempW As Word
      Dim Temp As Byte
      Dim BufferAddr As Word
    
    
      For Temp=0 To 31
         TempW=CRead BufferAddr
         Inc BufferAddr
         HRSOut Hex4 TempW
         HRSOut ","
      Next
    What I'm seeing is that the lower byte is read correctly. While the upper byte appears to be the lower byte of the next memory location with the upper two bits cleared.

    Data: 0000,0000,3180,28B8,3181,295A,01AF,01B0,01B1,01B1
    Read: 0000,0000,3880,01B8,1A81,2F5A,30AF,31B0,31B1,25B1

    Take the third value, 0x3880. The 80 is correct, and as you can see the lower byte matches everywhere. The upper byte is 38, while the next byte in my data has a value of B8. Clear bits 6 and 7, then you have 38. The same applies across the whole dataset.

    The CWrite command clearly states that when supplied with a word value it'll write only 14bits of that word (understandable). Nothing talks about this on the CRead or CRead16 commands, and there is no explanation of how to read the upper 6 bits of a 14 bit word. Yet the behaviour looks to be as though it is trying to read the upper byte, as it is stripping off the upper two bits in the process.

    Any ideas what is going on here?

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,247
    Thumbs Up
    Received: 375
    Given: 133
    Total Downloaded
    1.58 GB

    0 Not allowed!

    Default Re: Cread Word unexpected results

    What device is it?

    Now, virtually all devices are different from each other in the way they operate, even when they are from the same family!

    You are also reading 16-bits from a Cdata table, but only incrementing by 1. A word variable takes 2 bytes. Try Cread16, which is the main command to use now, the same as Cread8 and Cread32.
    Last edited by top204; 10th February 2019 at 17:32.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Junior Member mjturner's Avatar
    Join Date
    Dec 2003
    Posts
    88
    Thumbs Up
    Received: 14
    Given: 4
    Total Downloaded
    544.85 MB

    0 Not allowed!

    Default Re: Cread Word unexpected results

    It is a 16F15325 that i'm running this code on. Sorry, should have said!

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,247
    Thumbs Up
    Received: 375
    Given: 133
    Total Downloaded
    1.58 GB

    0 Not allowed!

    Default Re: Cread Word unexpected results

    I've done a bit of testing and Cread is working as expected on enhanced 14-bit core devices. This is one of the things they all have in common, thankfully. :-)

    Code:
        Device = 16F1939
        Declare Xtal = 32
       
        Declare Hserial1_Baud = 9600
    
        Dim MyFlash As Code = As Word $0000, $0000, $3180, $28B8, $3181, $295A, $01AF, $01B0, $01B1, $01B1
        
        Dim TempW As Word
        Dim Temp As Byte
        Dim BufferAddr As Word
    
        BufferAddr = AddressOf(MyFlash)
        For Temp = 0 To  31 
            TempW = CRead BufferAddr
            BufferAddr = BufferAddr + 2
            HRSOut Hex4 TempW
            HRSOut ","
        Next
    You would be better off using Cread16, as below:

    Code:
        Dim MyWord As Word
        Dim bIndex As Byte
        
        For bIndex = 0 To  9 
            MyWord = CRead16 MyFlash[bIndex]
            HRSOut IHex4 MyWord, ", "   
        Next 
    It is much more efficient in code use, and is easier to manipulate. Cread was an early manipulator of flash (code) memory, because, back then, most devices could not access their flash memory directly. Then as time progressed and all devices can read their flash, I thought of adding a better mechanism for it. i.e. Cread8, Cread16, and CRead32. And Cread64 on Proton24 to access Double size values (64-bit). Therre are also the cPtr8, cPtr16 and cPtr32 commands which work purely by reference to a flash memory address. I will be adding a hint to the compiler that Cread on its own, as well as Cdata are legacy commands and are not recommended.

    Also remember to indicate in the data table that the values are all Words, otherwise 8-bit values mixed with 16-bit values and 32-bit values will all jumble around, because the compiler then takes the actual "value" between the commas, and places them in flash memory based upon their bit-size. i.e. values below or equal to $FF will take 1 byte (8-bits), values between $0100 to $FFFF will take 2 bytes (16-bits), and values between $010000 to $FFFFFFFF will take 4 bytes (32-bits), and so will floating point values because in Proton, floats are 32-bit.
    Last edited by top204; 10th February 2019 at 18:08.

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Junior Member mjturner's Avatar
    Join Date
    Dec 2003
    Posts
    88
    Thumbs Up
    Received: 14
    Given: 4
    Total Downloaded
    544.85 MB

    0 Not allowed!

    Default Re: Cread Word unexpected results

    Thanks - but I'm not trying to read data as such, I'm trying to read the program itself. I want to access the full 14bit values. My understanding is that if I use a word directive then it will store 8 bits in two different code memory locations, rather than the 14bits in a single code memory location.

    My example was showing the expected 14bit values. I was showing a memory dump taken from my programmer vs what I was getting using the CRead command.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,247
    Thumbs Up
    Received: 375
    Given: 133
    Total Downloaded
    1.58 GB

    0 Not allowed!

    Default Re: Cread Word unexpected results

    You cannot use the compiler's Cread commands for that type of code memory reading because the compiler splits 16-bit values into 2 bytes and the Cread commands know this and manipulate themselves for it. Also, data is stored differently for data tables, to the actual mnemonic code data

    You will need to create a routine to read the mnemonic code data from flash memory. For example, on an enhanced 14-bit core device 16F1939, the routine below works:

    Code:
         Dim wEEDAT As EEDATL.Word
        Dim wEEADR As EEADRL.Word
    
        Dim MyWord As Word
        Dim wIndex As Word
    
        wEEADR = 0
        For wIndex = 0 To 9
            Clear EECON1bits_CFGS     ' Do not select Configuration Space
            Set  EECON1bits_EEPGD     ' Select Program Memory
            Set EECON1bits_RD         ' Initiate read
            Nop                       ' \ Required after a read setup
            Nop                       ' /
            MyWord = wEEDAT           ' Read from code memory   
            Swap MyWord.Byte0, MyWord.Byte1 ' Swap the bytes around
            Inc wEEADR                ' Increment the code memory address
            HRSOut Hex4 MyWord, ","
        Next
    For the 16F15325 device, it manipulates the NVM SFRs. See page 159 of the data sheet.

    I don't have the device setup for testing, but it should look something like this:

    Code:
         Dim wNVMADR As NVMADRL.Word
        Dim wNVMDAT As NVMDAT.Word
    
        Dim MyWord As Word
        Dim wIndex As Word
    
        wNVMADR = 0                         ' Start at address 0
        For wIndex = 0 To 9
            Clear NVMCON1bits_NVMREGS       ' Do not select Configuration Space
            Set NVMCON1bits_RD              ' Initiate read
            MyWord = wNVMDAT                ' Read from code memory   
            Swap MyWord.Byte0, MyWord.Byte1 ' Swap the bytes around
            Inc wNVMADR                     ' Increment the code memory address
            HRSOut Hex4 MyWord, ","
        Next
    See.... Even those devices are different, yet they are the same family. Accessing standard data in flash memory is different and uses an offset added to the address and the FSR0L\H or FSR1L\H SFRs and indirect access.

    What has happened to these code windows? They are dreadful now. In the window that I am creating the code they are perfectly aligned and set to Courier New, but when viewed, the alignment of the commands and comments is all over the place, and extra spaces are added all over, and the font is certainly not Courier New, which is why I think it is not aligning! It never used to be like this. It looks more like a messy Linux font that a neat Windows font?
    Last edited by top204; 10th February 2019 at 22:39.

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. playing with serial comm's and unexpected results on GLCD
    By pe1pme in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 19th January 2015, 16:51
  2. Replies: 1
    Last Post: 23rd May 2014, 09:11
  3. Unexpected PIC resets
    By RemonDePemon in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 1st November 2010, 02:20
  4. unexpected result with data an read
    By nigelstephens in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 21st April 2008, 08:02
  5. Unexpected PIC resets
    By rcurl in forum Proton Plus Compiler v3
    Replies: 23
    Last Post: 3rd August 2005, 20:50

Members who have read this thread since 8th July 2019, 01:19 : 0

Actions :  (Set Date)  (Clear Date)

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