Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
Static Public Member Functions | List of all members
modules::permanent_storage::FilamentLoaded Class Reference

Read and store last filament loaded to nozzle. More...

#include <permanent_storage.h>

Static Public Member Functions

static bool get (uint8_t &filament)
 Get last filament loaded. More...
 
static bool set (uint8_t filament)
 Set filament being loaded. More...
 

Detailed Description

Read and store last filament loaded to nozzle.

800(data) + 3(status) EEPROM cells are used to store 4 bit value frequently to spread wear between more cells to increase durability.

Expected worst case durability scenario:
Print has 240mm height, layer height is 0.1mm, print takes 10 hours, filament is changed 5 times each layer, EEPROM endures 100 000 cycles
Cell written per print: 240/0.1*5/800 = 15
Cell written per hour : 15/10 = 1.5
Fist cell failure expected: 100 000 / 1.5 = 66 666 hours = 7.6 years

Algorithm can handle one cell failure in status and one cell in data. Status use 2 of 3 majority vote. If bad data cell is detected, status is switched to next key. Key alternates between begin to end and end to begin write order. Two keys are needed for each start point and direction. If two data cells fails, area between them is unavailable to write. If this is first and last cell, whole storage is disabled. This vulnerability can be avoided by adding additional keys and start point in the middle of the EEPROM.

It would be possible to implement twice as efficient algorithm, if separate EEPROM erase and EEPROM write commands would be available and if write command would allow to be invoked twice between erases to update just one nibble. Such commands are not available in AVR Libc, and possibility to use write command twice is not documented in atmega32U4 datasheet.

Member Function Documentation

◆ get()

bool modules::permanent_storage::FilamentLoaded::get ( uint8_t &  filament)
static

Get last filament loaded.

Parameters
[in,out]filamentfilament number 0 to 4
Return values
truesuccess
falsefailed

◆ set()

bool modules::permanent_storage::FilamentLoaded::set ( uint8_t  filament)
static

Set filament being loaded.

Always fails, if it is not possible to store status. If it is not possible store filament, it tries all other keys. Fails if storing with all other keys failed.

Parameters
filamentbottom 4 bits are stored but only value 0 to 4 passes validation in FilamentLoaded::get()
Return values
truesuccess
falsefailed

The documentation for this class was generated from the following files: