View previous topic :: View next topic |
Author |
Message |
hamedhamedi
Joined: 12 Feb 2012 Posts: 70
|
Posted: Wed Dec 03, 2014 8:14 am Post subject: EEPROM and SRAM problems |
|
|
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 |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Dec 03, 2014 10:30 am Post subject: |
|
|
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 |
|
|
hamedhamedi
Joined: 12 Feb 2012 Posts: 70
|
Posted: Wed Dec 03, 2014 10:57 am Post subject: |
|
|
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 |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Thu Dec 04, 2014 2:16 am Post subject: |
|
|
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 |
|
Back to top |
|
|
|