Menu

DATA BLOCKS: New capability

Anobium
2024-06-10
2025-07-02
  • Anobium

    Anobium - 2024-06-10

    Just added data blocks to the compiler. You can now add data blocks, multiples, to you program. They can be any size to the maximum of the chips Progmem.

    To use... This is a very short data block the video shows a mega data block.

    DATA BlockName1
      0x00, 0x01 
    END DATA
    

    To read this specific data block, see code below. For a more comprehensive approach - see the video.

    For Offset = 1 to 2
    ProgRead ( @BlockName1 + OffSet, retValue
    HserSend retValue
    Next

    The key to using is the naming of the data block and the '@' to reference the data block.

    Simple.

    Enjoy

     
    ❤️
    3
  • Manfred Mornhinweg

    To further explain this to other users:

    The program for which I needed this data block capability is one that generates the drive signals for a pure sine wave DC-AC inverter. Generating the sine pulse width modulation signals, with output voltage regulation and everything, would be very easy when using a CPU that has enough number crunching capability to make about 50,000 multiplications per second. So for each pulse one can calculate the sine value, multiply it by the gain value, and send it to the PWM hardware.

    Alas, an 8-bit PIC can't multiply that fast. But it has a lot of program memory. So my approach was to place many quarter-wave sine tables of different amplitudes in memory, and have the program read the proper value for each pulse from the proper table. This avoids all need for multiplication.

    To create a 50Hz sine wave at a 20kHz sampling rate, when using a 32MHz system clock, each pulse can be maximally 1600 clock cycles long. So the maximum value I need to store in my tables is 1600. That's too large for a byte variable, but fits easily in the 14 bit word length of a PIC16's program memory! It would be a waste to use two memory locations for each value.

    GCB already had a way to efficiently read 14-bit values from program memory: The PROGRAMREAD sentence. But it lacked a way to efficiently put the data table into the source code! So I had to work around this by writing a small program that stuffs my data table into the .hex file after GCB creates it, and before it's written to the PIC. That worked well, but was a little awkward.

    The assembler already had the required command, DW, so it should not be too hard to implement it in GCB. And that's what Anobium did, on my request. Thanks! I have now modified my program to include my sine table data using the new functionality, and it works great.

    For those who want to see it, I have attached my program, as it is right now, in the middle of development. It already works fine, but I still need to add some functionality to control other parts of my inverter, add some bells and whistles, and then tidy it up.

     
  • Roger Jönsson

    Roger Jönsson - 2025-07-02

    Any drawbacks compared to using lookup tables?

     
  • Anobium

    Anobium - 2025-07-02

    No drawbacks just advantages. Data Block can be large, very large. Page on non-18f is not a limitation, just the amount of Free program memory.

     
    👍
    1

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.