View previous topic :: View next topic |
Author |
Message |
dl7sep
Joined: 26 Feb 2006 Posts: 81
|
Posted: Sat Mar 07, 2015 9:09 pm Post subject: Eram Multi Array Problem |
|
|
Hello , i want to handle Eram Array with Multi Array.
Is there a chance, to get it running?
Code:
' **********************************************************************
' ** Program name: Test_Multi_Array **
' ** Compiler : BASCOM AVR, ( V2.0.7.8.001) **
' ** ATMEGA32 **
' ** **
' ** **
' ** Referenz Prozessor = 16.0000 MHz **
' ** Date: 07.03.2015 **
' ** **
' ** **
' ** Written by: Sepp Bartl **
' **********************************************************************
'$sim
$regfile = "m32def.dat" 'use the ATMEGA32 file
$crystal = 16000000
$hwstack = 128 '64 'default use 32 for the hardware stack
$swstack = 128 '16'default use 10 for the SW stack
$framesize = 128 '32'default use 40 for the frame space
Config Base = 0
$baud = 57600
Config Base = 0
'-------------------------------------------------------------------------------
Wait 1
'-------------------------------------------------------------------------------
'Variablen Global
Dim Multiarray(16 , 16)as Eram Byte
Dim X As Byte
Dim Y As Byte
Dim Value As Byte
'-------------------------------------------------------------------------------
Print " OUTPUT MULTI ARRAY "
For Y = 0 To 15
For X = 0 To 15
Value = Multiarray(x , Y)
Print "X= " ; X ; " Y= " ; Y ; " Value= " ; Value
Next X
Next Y
'
'-------------------------------------------------------------------------------
Do
Loop
End
'-------------------------------------------------------------------------------[code]
Appendix: EE-Prom File, Output File.
The Value repeats 16 Times 0-15, but i expected 0-255.
What is my mistake?
Many thanks, for helping.
Josef
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sun Mar 08, 2015 7:48 am Post subject: |
|
|
Hi,
I'm not sure if multi array works with eram, but I know print has problems with multi array. So rather than reading directly from a multi array with print, first copy the variable you want to print into a normal variable then print that:-
Code: |
a=Multiarray(1,3)
print a
|
maybe that's enough.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
dl7sep
Joined: 26 Feb 2006 Posts: 81
|
Posted: Sun Mar 08, 2015 10:47 am Post subject: |
|
|
Hello Ian,
Quote: | a=Multiarray(1,3)
print a |
that i have done in the code bevor
Quote: | Value = Multiarray(x , Y)
Print "X= " ; X ; " Y= " ; Y ; " Value= " ; Value |
Value (Byte) is a separat Value, and this is used for print.
So i think i must handle this with a normal array like this:
Code: | ' **********************************************************************
' ** Program name: Test_Multi_Array_1 **
' ** Compiler : BASCOM AVR, ( V2.0.7.8.001) **
' ** ATMEGA32 **
' ** **
' ** **
' ** Referenz Prozessor = 16.0999 MHz **
' ** Date: 08.03.2015 **
' ** **
' ** **
' ** Written by: Sepp Bartl **
' **********************************************************************
'$sim
$regfile = "m32def.dat" 'use the ATMEGA32 file
$crystal = 16000000
$hwstack = 32 '64 'default use 32 for the hardware stack
$swstack = 32 '16'default use 10 for the SW stack
$framesize = 32 '32'default use 40 for the frame space
Config Base = 0
$baud = 57600
'-------------------------------------------------------------------------------
'Variablen Global
Dim Array(256) As Eram Byte
Dim X As Byte
Dim Y As Byte
Dim Value As Byte
Dim Adress As Byte
Wait 1
'-------------------------------------------------------------------------------
Print " Ausgabe Kennfeld "
For Adress = 0 To 255
Value = Array(adress)
Y = Adress / 16
X = Adress Mod 16
Print "X= " ; X ; " Y= " ; Y ; " Wert= " ; Value
Next Adress
'
'-------------------------------------------------------------------------------
Do
Loop
End
'------------------------------------------------------------------------------- |
Many thanks, Josef |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sun Mar 08, 2015 10:59 am Post subject: |
|
|
Hi,
Sorry I didn't notice that.
Quite often when I have a lot of data that needs to be saved to eeprom, I create an array in ram that is loaded with data from the eeprom and the eeprom is only written when something changes. Using overlay I just create a byte array that's large enough to cover all the data from the eeprom. Something like:-
Code: |
'--The following parameters are written to the eeprom--------------------------
Dim Zeropoint(10) As Word 'Raw zero 20bytes
Dim Scale_factor(10) As Single '1pascal=RAW units 40bytes
Dim Smoothing_factor(10) As Byte '1pascal=RAW units 10bytes
Dim Eepromparameter(10) As Word '20bytes
Dim Spare As Dword 'Reserve for EEPROM params
Spare = 0
'--END OF EEPROM LIST-------------------------------------------------------
Dim Eeprom_parameters(92) As Byte At Zeropoint(1) Overlay 'OVERLAY for EEPROM
Dim Eeprom_checksum_calc As Word 'EEPROM OK FLAG
Dim Eeprom_checksum As Word '2 Byte EEPROM chacksum
'-----------------------------------------------------------------------------
Save2eeprom: '-- save to eeprom
Dim Eeprom_address As Byte
Dim Ep As Byte:
Eeprom_address = 10 'EEPROM start address
Eeprom_checksum_calc = &HDEAD 'Starting point for checksum
For Ep = 1 To 92 'Loop though parameters
Eeprom_checksum_calc = Eeprom_checksum_calc + Eeprom_parameters(ep)
Writeeeprom Eeprom_parameters(ep) , Eeprom_address 'save to eeprom
Incr Eeprom_address 'next address
Next Ep
Writeeeprom Eeprom_checksum_calc , 5 'save checksum
Return
Loadfromeeprom: '-- load from eeprom
Eeprom_address = 10 'EEPROM start address
Eeprom_checksum_calc = &HDEAD 'Starting point for checksum
For Ep = 1 To 92 'Loop though parameters
Readeeprom Eeprom_parameters(ep) , Eeprom_address 'read from eeprom
Eeprom_checksum_calc = Eeprom_checksum_calc + Eeprom_parameters(ep)
Incr Eeprom_address
Next Ep
Readeeprom Eeprom_checksum , 5 'Read eeprom checksum
Print #2 , "EEPROM Checksum " ; Eeprom_checksum_calc ; " " ; Eeprom_checksum
Return
|
That way you can have the best of both worlds (fast access from RAM and permanent storage in EEPROM).
The only limitation is the parameters need to be manually written to the eeprom when anything changes.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
dl7sep
Joined: 26 Feb 2006 Posts: 81
|
Posted: Sun Mar 08, 2015 12:22 pm Post subject: |
|
|
Quote: | I create an array in ram that is loaded with data from the eeprom and the eeprom is only written when something changes. Using overlay |
Ok, that is a good idea, but i want to save sram, and for that with the multiarray with eram i need only one byte for x, one Byte for y, one byte for result.
And the array need a lot of space 256 bytes.
I have no experience about the timing between sram and eram bytes. To write the eeprom there is no problem to do this with overlay ore what ever.
Many thanks, Josef |
|
Back to top |
|
|
dl7sep
Joined: 26 Feb 2006 Posts: 81
|
Posted: Wed Mar 11, 2015 8:16 pm Post subject: |
|
|
Is there no more answer about ERAM multiarray problem? |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Mar 12, 2015 9:20 am Post subject: |
|
|
dl7sep wrote: | Is there no more answer about ERAM multiarray problem? |
What do you like to hear? Obviously the ERam multi-array is still in a roadworks-state, means it won't work.
So it's either an issue for writing to support, or writing your own functions to access the EEProm as multi-array.
The latter is less comfortable, but it will do, till the road is nicely paved. |
|
Back to top |
|
|
dl7sep
Joined: 26 Feb 2006 Posts: 81
|
Posted: Thu Mar 12, 2015 4:15 pm Post subject: |
|
|
Hello Ludwig,
many thanks for your response.
For me it is enough, to know there is no mistake of mine.
In the example without ERAM Multi-Array i have a solution.
When there is a solution from MCS, i think i can save a little time in the task, thats all.
Best Regards Josef |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Mar 12, 2015 5:10 pm Post subject: |
|
|
Ok, fine
As I felt some readers had tiny problems with understanding of multi-arrays, here is some small code done in a few minutes.
It shows, what actually happens inside Bascom's multi-array.
As "Overlay" was mentioned, there's no need for overlay here.
Code: | $Regfile = "m328def.dat"
$Crystal = 4000000
$hwstack = 40
$swstack = 16
$framesize = 32
$sim
Config Base = 0
Const Size_X = 16
Const Size_Y = 16
Const MA_Size = Size_X * Size_Y
Declare Sub MA_Write(ByVal X As Byte , ByVal Y As Byte , ByVal Wr_Val As Byte)
Declare function MA_Read(ByVal X As Byte , ByVal Y As Byte) As Byte
Dim MA_Container(MA_Size) As ERam Byte
Dim X As Byte
Dim Y As Byte
Dim Value As Byte
MA_Write 1 , 1 , 69
Print " OUTPUT MULTI ARRAY "
For Y = 0 To 15
For X = 0 To 15
Value = MA_Read(x , Y)
Print "X= " ; X ; " Y= " ; Y ; " Value= " ; Value
Next X
Next Y
Do : Loop
Sub MA_Write(ByVal X As Byte , ByVal Y As Byte , ByVal Wr_Val As Byte)
Local EEPos As Word
EEPos = Y * Size_X
EEPos = EEPos + X
MA_Container(EEPos) = Wr_Val
End Sub
function MA_Read(ByVal X As Byte , ByVal Y As Byte) As Byte
Local EEPos As Word
EEPos = Y * Size_X
EEPos = EEPos + X
MA_Read = MA_Container(EEPos)
End Function |
You can try it out in the simulator.
Btw., all the ByVals are only there for forwarding a value or a constant, but you surely know. |
|
Back to top |
|
|
dl7sep
Joined: 26 Feb 2006 Posts: 81
|
Posted: Thu Mar 12, 2015 6:30 pm Post subject: |
|
|
Ok,
your code use Sub Functions,
but you do in principle the same as I:
Code: | ' **********************************************************************
' ** Program name: Klappensteuerung **
' ** Compiler : BASCOM AVR, ( V2.0.7.8.001) **
' ** ATMEGA32 **
' ** **
' ** **
' ** Referenz Prozessor = 16.0000 MHz **
' ** Date: 07.03.2015 **
' ** **
' ** **
' ** Written by: Sepp Bartl **
' **********************************************************************
'$sim
$regfile = "m32def.dat" 'use the ATMEGA32 file
$crystal = 16000000
$hwstack = 64 '64 'default use 32 for the hardware stack
$swstack = 64 '16'default use 10 for the SW stack
$framesize = 64 '32'default use 40 for the frame space
Config Base = 0
$baud = 115200 '57600
Config Watchdog = 1024 'reset after 1024 mSec
'-------------------------------------------------------------------------------
'GND = DDS RST
'-------------------------------------------------------------------------------
'Define Pins
Ddrb.1 = 0 'PB1/T1 auf Eingang setzten(Zähler Eingang)
'-------------------------------------------------------------------------------
'Datenrichtung Port...
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'Variablen Global
Dim Kennfeld(256) As Eram Byte 'Wertebereich im EE-Prom 16x16 Bytes
Dim X As Byte 'Zeiger X Position EE-Prom
Dim Y As Byte 'Zeiger Y Position EE-Prom
Dim Wert As Byte 'Wert im EE-Prom
Dim Adress As Byte 'Adresse EE-Prom
Dim Zeit As Word 'Für Timerinterrupt
Dim Random As Byte 'Zufallszahl für Test
Dim Send As Bit 'Für Testroutine senden
Dim I As Byte 'Serielle Zeichenerkennung ? oder #
Dim Eprom_data As String * 15 'Serieller Eingangsdatenstring
Dim Ar(4) As String * 3 '3x Array + Nullbytearray
Dim Bcount As Byte 'Für Splitfunktion nötig
Config Serialin = Buffered , Size = 15 'Serieller Eingangsbuffer
Dim Cnt As Word 'Gezählte Impulse
Dim X_mess As Word 'X Variable für Umrechnung aus Frequenzmessung
Dim Y_mess As Word 'Y Variable für Umrechnung aus AD-Wandler
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'Constanten
Const Timer_reload = 99 'Für 10ms bei 16.000 MHz Prescale 1024
'-------------------------------------------------------------------------------
'Timer1 Config Counter
Config Timer1 = Counter , Edge = Rising , Noise Cancel = 1
'-------------------------------------------------------------------------------
'Config Timer/Counter
On Timer0 Timer_interrupt
Config Timer0 = Timer , Prescale = 1024 '16.0000/1024/= 15.625(255-156=99) 15625/156=100.1 = 10ms
Enable Timer0 'Timer0 ein
Enable Interrupts 'Enable Interrupts
Timer0 = Timer_reload
Start Timer0 'Start Timer0
'-------------------------------------------------------------------------------
'Config ADC
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Admux = &H40 'Messkanal 0
Adcsra.adsc = 1 'Startet AD-Messung
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
Start Watchdog 'start the watchdog timer
'-------------------------------------------------------------------------------
Do
Reset Watchdog
'------------------AD-Wandlung--------------------------------------------------
If Adcsra.adsc = 0 Then 'Wenn AD-Wandlung fertig
Y_mess = Adc 'Messwertübergabe
Adcsra.adsc = 1 'Startet AD-Messung
End If
'------------------SendeRoutine-------------------------------------------------
If Send = 1 Then
X_mess = Cnt * 15 '100 Pulse = 10000 U/min skalliert auf 15
X_mess = X_mess / 100
If X_mess > 15 Then X_mess = 15 'Wertbegrenzung
X = X_mess
Y_mess = Y_mess / 68 'Wert 1023 / 68 ergibt ~15
If Y_mess > 15 Then Y_mess = 15 'Wertbegrenzung
Y = Y_mess
Adress = Y * 16 'EE-Adresse berechnen
Adress = Adress + X
Wert = Kennfeld(adress) 'Wert aus EE-Prom lesen
Print "$";
Print X ; "," ; Y ; "," ; Wert;
Print "!"
Send = 0
End If
'------------------EE-Prom-beschreiben------------------------------------------
I = Inkey()
If I = 35 Then '# Wert im EE-Prom speichern
Input Eprom_data Noecho
Bcount = Split(eprom_data , Ar(1) , ",")
X = Val(ar(1))
Y = Val(ar(2))
Wert = Val(ar(3))
Adress = Y * 16
Adress = Adress + X
Writeeeprom Wert , Adress
Print "$";
Print X ; "," ; Y ; "," ; Wert;
Print "!"
I = 0
End If
'-----------------Tabelle-senden------------------------------------------------
If I = 63 Then '? Tabelle an PC senden
Disable Interrupts 'Tabelle senden benötigt viel Zeit.
Adress = 0
Y = 0
X = 0
Print "$";
For Adress = 0 To 255
Wert = Kennfeld(adress)
Y = Adress / 16
X = Adress Mod 16
Print X ; "," ; Y ; "," ; Wert 'CR+LF muss gesendet werden!
Next Adress
Print "!"
I = 0
Enable Interrupts
End If
'-------------------------------------------------------------------------------
Loop
End
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
Timer_interrupt:
Timer0 = Timer_reload 'Interrupt Timer Vorgabewert laden
Incr Zeit
If Zeit = 10 Then '100ms vergangen
Zeit = 0
Send = 1
End If
Cnt = Timer1 'Gezählte Impulse abholen
Timer1 = 0 'Counter Reset
Return
'------------------------------------------------------------------------------- |
Sorry the comment in the code is in german.
Regards
Jsoef |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Mar 12, 2015 8:37 pm Post subject: |
|
|
dl7sep wrote: | your code use Sub Functions,
but you do in principle the same as I |
Sure, it's no rocket science.
As I've wanted to show a sample, it made sense to encapsulate the code, so it behaves kinda Bascom function. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|