Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

EEPROM and SRAM problems

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
hamedhamedi

Bascom Member



Joined: 12 Feb 2012
Posts: 70

PostPosted: Wed Dec 03, 2014 8:14 am    Post subject: EEPROM and SRAM problems Reply with quote

Hello
i have a circuit with a opto counter connected to a dc motor.
i want to save 2 position of motor in memory and set new position according to requested input.
circuit drive with backup battery to save current position of motor without main power.
now i have 2 question:
1-i want to have current position of motor every time,even if watchdog enabled and microcontroller restart!
from bascom avr help i found that i can use $noramclear to save sram value even after restart,but sometimes after restart the microcontroller do not work correctly!
so i want to save the value of variable related to current position and then initialize sram by my program.but i dont know how to clear all sram before start of program!

the microcontroller i use is atmega64.
2-i want to save 2 position of motor to eeprom and a default value for this 2 position.how can i set a initial value to a EEprom variable?
i do not want to change this value to its default after each restart!
i want to have a EEprom variable with a pre defined value just after first startup sfter programing of microcontroller!

Thankyou

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1136

poland.gif
PostPosted: Wed Dec 03, 2014 10:30 am    Post subject: Reply with quote

My knowledge is that every declared variable is cleared/set to zero on program start so You don`t need to think about that.
If You know how $noramclear work then dont be suprised. I suggest wrote programm properly so Watchdog will not have to restart micro.
For eeprom value You can do like that
Code:

Dim min_pos As Byte, max_pos As Byte

 Readeeprom min_pos,1
 Readeeprom max_pos,2

 If min_pos > 254 Then min_pos = 20 'if eeprom is empty after programming with FF(255)
 If max_pos > 254 Then max_pos = 100

Do
'You can change data in eeprom antime
Loop

$eeprom ' this will generate Eep file near Hex file, but if You forget to program then protection is in code
Data 0,20,100
$data


Have a nice day
Back to top
View user's profile Visit poster's website
hamedhamedi

Bascom Member



Joined: 12 Feb 2012
Posts: 70

PostPosted: Wed Dec 03, 2014 10:57 am    Post subject: Reply with quote

first thank you
Quote:
My knowledge is that every declared variable is cleared/set to zero on program start so You don`t need to think about that.


i test it,when i use $noramclear , all variables are same as befor reset of microcontroller

Quote:
I suggest wrote programm properly so Watchdog will not have to restart micro.


some times reset may occur, we can not predict noise in industrial environment and we should take care about action of microcontroller against reset, so we need to use watchdog during power on of circuit with main supply.

about your code it is very nice,thank you.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1136

poland.gif
PostPosted: Thu Dec 04, 2014 2:16 am    Post subject: Reply with quote

I forgot to write that when working with eeprom necessarily must enable FUSE BODEN because with uncertain power memory contents can be blurred.
I saw it with my own eyes after the storm Very Happy
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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