News:

Let's find out together what makes a PIC Tick!

Main Menu

Correct usage of Edata ?

Started by TimB, Nov 26, 2025, 09:44 AM

Previous topic - Next topic

TimB


Hi All

I have some code and I need eeprom storage I'm trying to figure out the correct way to use Edata to allocate the pointers

Device is a pic18f27Q10

For now I'm using

ceBledPWMAddr Edata as word 512   

But when I look at the ASM I see

; EEPROM DATA
    org 0X310000
    db 0,2 

And when I read it back using

Dim wBottomOptoThresh as word

wBottomOptoThresh = Eread ceBledPWMAddr

wBottomOptoThresh end up with 0


Any idea what I'm doing wrong?


TimB


Well 0x0200 is actually 512

Just need to work out why I'm reading back 0

top204

#2
I'm not getting any problems with reading on-board EEPROM on a real PIC18F27Q10 device. An example I created is the code listing below:

'
'  /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\    \/\\\                                                /\\\          /\\\
'  \/\\\\\\\\\\\/        /\\\\\    /\\\\\\\\\\    /\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'    \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\    \/\\\        \/\\\        /\\\\\\\\\\
'      \/\\\    \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\    \/\\\ /\\  /\\\/////\\\
'      \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\  \//\\\\\\\\/\\
'        \///        \///    \/////    \//////////    \//////////      \/////        \/////    \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Code listing template for an Internal Oscillator operating at 64MHz on a PIC18F27Q10 device.
' Written for the Positron8 BASIC Compiler by Les Johnson.
'
    Device = 18F27Q10                              ' Tell the compiler what device to compile for
    Declare Xtal = 64                              ' Tell the compiler what frequency the device is operating at (in MHz)
    Declare Auto_Heap_Strings = On                 ' Make all Strings "Heap" types, so they always get placed after standard variables
    Declare Auto_Variable_Bank_Cross = On          ' Make sure all multi-byte variables remain within a single RAM bank
'
' Setup USART1
'
    Declare Hserial_Baud = 9600                    ' Set the Baud rate for USART1
    Declare HRSOut1_Pin  = PORTC.6                 ' Tell the compiler to setup pin PORTC.6 for USART1 Tx
    Declare HRSIn1_Pin   = PORTC.7                 ' Tell the compiler to setup pin PORTC.7 for USART1 Rx
'
' Create some EEPROM data
'
EE_Data0 EData As Word 512, 513, 514, 515
'
' Create any global variable here
'
    Dim wOffset As Word
    Dim wValue As Word
   
'---------------------------------------------------------------------------
' The main program starts here
'
Main:
    Setup()                                        ' Setup the program and the peripherals

    wValue = ERead EE_Data0                        ' Read from on-board EEPROM
    HRSOut1Ln Dec wValue                           ' Display the value that was read
       
    For wOffset = EE_Data0 To EE_Data0 + 6 Step 2  ' Create a loop to read four 16-bit values from on-board EEPROM
        wValue = ERead wOffset                     ' Read from on-board EEPROM
        HRSOut1Ln Dec wValue                       ' Display the value that was read
    Next
   

'---------------------------------------------------------------------------
' Setup the program and any peripherals
' Input    : None
' Output   : None
' Notes    : None
'
Proc Setup()

EndProc

'------------------------------------------------------------------------------------------------
' Setup the fuses to use the internal oscillator to operate at 64MHz on a PIC18FxxQ10 device.
' With RA6 and RA7 as I/O lines
'
Config_Start
    FEXTOSC = Off                                  ' External Oscillator not enabled
    RSTOSC = HFINTOSC_64MHZ                        ' HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    WDTE = Off                                     ' WDT disabled
    CLKOUTEN = Off                                 ' CLKOUT function is disabled
    CSWEN = On                                     ' Writing to NOSC and NDIV is allowed
    FCMEN = Off                                    ' Fail-Safe Clock Monitor disabled
    MCLRE = EXTMCLR                                ' MCLR pin (RE3) is MCLR
    PWRTE = On                                     ' Power up timer enabled
    LPBOREN = Off                                  ' Low power BOR is disabled
    BOREN = On                                     ' Brown-out turned on
    BORV = VBOR_245                                ' Brown-out Reset Voltage (VBOR) set to 2.45V
    ZCD = Off                                      ' ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = Off                                  ' PPSLOCK bit can be cleared and set multiple times
    STVREN = Off                                   ' Stack Full/Underflow Reset Enable bit->Stack full/underflow will not cause Reset
    XINST = Off                                    ' Extended Instruction Set Enable bit->Extended Instruction Set and Indexed Addressing Mode disabled
    WDTCPS = WDTCPS_14                             ' Watchdog Divider ratio 1:524299 (16 seconds)
    WDTCWS = WDTCWS_7                              ' WDT Window Select bits->window always open (100%)
    WDTCCS = LFINTOSC                              ' WDT reference clock is the 31.2kHz HFINTOSC output
    WRT0 = Off                                     ' Block 0 (000800-001FFF) not write-protected
    WRT1 = Off                                     ' Block 1 (002000-003FFF) not write-protected
    WRT2 = Off                                     ' Block 2 (004000-005FFF) not write-protected
    WRT3 = Off                                     ' Block 3 (006000-007FFF) not write-protected
    WRTC = Off                                     ' Configuration registers (300000-30000B) not write-protected
    WRTB = Off                                     ' Boot Block (000000-0007FF) not write-protected
    WRTD = Off                                     ' Data EEPROM not write-protected
    SCANE = Off                                    ' Scanner module is not available for use, SCANMD bit can control the module
    LVP = Off                                      ' HV on MCLR/VPP must be used for programming
    Cp = Off                                       ' User NVM code protection disabled
    CPD = Off                                      ' Data NVM code protection disabled
    EBTR0 = Off                                    ' Block 0 (000800-001FFF) not protected from table reads executed in other blocks
    EBTR1 = Off                                    ' Block 1 (002000-003FFF) not protected from table reads executed in other blocks
    EBTR2 = Off                                    ' Block 2 (004000-005FFF) not protected from table reads executed in other blocks
    EBTR3 = Off                                    ' Block 3 (006000-007FFF) not protected from table reads executed in other blocks
    EBTRB = Off                                    ' Boot Block (000000-0007FF) not protected from table reads executed in other blocks
Config_End

On the serial terminal it displays:
512
512
513
514
515


Which are correct, and in the assembler listing the data is held as:

;---------------------------------------------
; EEPROM DATA
    org 0X310000
    db 0,2,1,2
    db 2,2,3,2


Which is correct.

Make sure you use a real device Tim, and not just the simulator.


TimB



Thanks Les

I'm still waiting on a test board, so I was running in a VSM, obviously a bad move.

top204

#4
If you have one of my earlier Amicus18 boards, or one of John's Amicus8 boards, just plug a device into it for testing code.


John Lawton

Quote from: top204 on Nov 26, 2025, 02:48 PMIf you have one of my earlier Amicus18 boards, or one of John's Amicus16 boards, just plug a device into it for testing code.

A lot cheaper to buy/run than the Proteus Simulator!

https://easy-driver.co.uk/Amicus/

John

TimB


I made the purchase John as I have been meaning to for weeks.

I like the VSM as I can do stuff that would be hard with real hardware. eg Coms between 2 boards and work out timings. However I need sanity checks as my Nano board with the 18f47Q10 cannot PWM on 4 channels. The VSM cannot perform ADC properly and now I find out Eread does not work. Ewrite does though.

Labcenter is good in that if you report an issue they do fix it. However my license ran out a couple of months back so will not benefit. Also I generally spend a long time trying to prove the fault but then find out I was wrong. Not much fun...
     

top204

The proteus simulator does come in handy sometimes, for simple tasks.

However, in recent years, I have come to "never" trusting it, and it is one of those: "many items, poor quality" products that seem so popular these days. So it is a very expensive toy, that is good to play with some times.

Regards
Les