openplc80
 
Hello OpenPLC team,
 
Arduino boards lack RETAIN memory, which limits both educational use and DIY projects. A “retain_safe” type that writes only on change, limits write frequency, and restores at startup would make persistent variables practical and safe. This could be transparent for the Arduino platform, with “RETAIN” handled internally as “retain_safe”.
 
Thanks!
Reply 0 0
thiagoralves
This would increase the scan cycle time significantly as writing to flash is much more expensive than writing to RAM
Reply 0 0
openplc80
Yes writing to flash is a lot slower than writing to RAM, but this can be handled with a “retain_safe” approach: write only when the value changes and enforce a minimum interval between writes. With this, the scan cycle impact is negligible, EEPROM is preserved, and Arduino users get a realistic RETAIN experience for teaching and DIY projects.
 
For a single byte, the EEPROM write time on an ATmega processor is around 4 ms. For most small projects, a couple of bytes of retain memory is enough. I think this is technically doable without any significant impact on cycle times, which makes the feature both practical and safe for typical educational or DIY applications.
 
In addition, AVR microcontrollers support non-blocking EEPROM writes: the CPU can continue executing instructions while the EEPROM controller completes the write in the background. Leveraging this feature would further minimize any impact on the PLC scan cycle.
 
By setting the EEMPE and then EEPE bits in the EECR register, the EEPROM controller handles the write in the background. The CPU can continue executing instructions while the write completes (≈4 ms). When finished, the EEPE bit clears automatically, indicating the EEPROM is ready for the next write.
Reply 0 0
Reply