EEPROM question

2 Channel generator is working Ok in # 2.
My problem is that amplitude on both channels are the same when I turn OFF/ON the power.
How to make amplitude Channel 2 as is stored in EEPROM so, turn OFF/ON the power will not effect on amplitude Channel 1 ?

#1
//amplitude Channel 1= amplitude Channel 2
int amp = 35;
val1[i] = 50 + amp * sin(stp * i);   //Channel 1
val2[i] = val1[i];                   //Channel 2

val2[i] = 50 + amp * sin( stp * i + shift * 0.1 * 6.2831 / 360);

#2
//amplitude Channel 1!= amplitude Channel 2
int amp2 = Value stored in EEPROM //Channel 2
int amp = 35;
val1[i] = 50 + amp * sin(stp * i);
val2[i] = val1[i];

val2[i] = 50 + amp * sin( stp * i + shift * 0.1 * 6.2831 / 360);

///////////////////////////
init_wave();
EEPROM.read(0, (uint16*)&shift);
EEPROM.read(500);  // // EEPROM for amp
get_wave(shift);

Use eeprom.get to read and eeprom.put to write.

That way there is no issue reading or writing variables that ain't byte.

That is quite simple, and the answer is [MISSING CONTENT], so there you have it :slight_smile:

Hard to help, when you post partial code in which the data types are not revealed..

then I have this error

amplitude_not_equal:145: error: 'class EEPROMClass' has no member named 'get'

EEPROM.get(500, (uint16*)&amp);

^

amplitude_not_equal:178: error: 'class EEPROMClass' has no member named 'get'

EEPROM.get(500); // // EEPROM for amp

^

C:\Users\OWNER\Desktop\start over 2\amplitude_not_equal\amplitude_not_equal.ino: In function 'void process_key_amp(int, debounce_info*)':

amplitude_not_equal:250: error: 'class EEPROMClass' has no member named 'put'

EEPROM.put(500, amp);

^

Using library EEPROM in folder: C:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\libraries\EEPROM (legacy)
exit status 1
'class EEPROMClass' has no member named 'get'

The code

//amplitudy te same dla u1 i u2

#define SAMPLES 100

#define DEBOUNCE_DELAY 10

#define DEBOUNCE_IDLE 0
#define DEBOUNCE_ACTIVE 1

#include <libmaple/dma.h>
#include <EEPROM.h>

struct debounce_info
{
  int start, state;
  int16 shift;
} left, right, up, down;

dma_tube_config dma_cfg, dma_cfg2;

int flag1 = 0;
int flag2 = 0;

int out1 = PB7;
int out2 = PA8;

int val1[SAMPLES];
int val2[SAMPLES];

int phasep = PB8;
int phasen = PB5;
int ampp = PB9;
int ampn = PB6;

int16 shift = 0;
/////////////////////////////
//int amp2 =
/////////////////////////////
int amp = 35;
int cnt = 0;
int time_track = 0;
float stp = 6.2831 / SAMPLES;
int ret = 17;

timer_dev *dev1 = PIN_MAP[out1].timer_device;
timer_dev *dev2 = PIN_MAP[out2].timer_device;
uint8 cc_channel1 = PIN_MAP[out1].timer_channel;
uint8 cc_channel2 = PIN_MAP[out2].timer_channel;

void fun()
{
  flag1++;
}

void fun2()
{
  flag2++;
}
////////////////////////////////////////////////
all code doesn't fit - it is to long
/////////////////////////////////////////////

  {
   
    val1[i] = 50 + amp * sin(stp * i);
    val2[i] = val1[i];
  }
}

void get_wave(int16 shift)
{
  int i;
  for (i = 0; i < SAMPLES; i++)
  {
    val2[i] = 50 + amp * sin( stp * i + shift * 0.1 * 6.2831 / 360);
  }
}

void setup() {
 // EEPROM for amp
  EEPROM.get(500, (uint16*)&amp); 
  int i;
  pinMode(out1, PWM);
  pinMode(out2, PWM);
  pinMode(phasep, INPUT_PULLDOWN);
  pinMode(phasen, INPUT_PULLDOWN);
  pinMode(ampp, INPUT_PULLDOWN);
  pinMode(ampn, INPUT_PULLDOWN);

  memset(&left, 0, sizeof(debounce_info));
  memset(&right, 0, sizeof(debounce_info));
  memset(&up, 0, sizeof(debounce_info));
  memset(&down, 0, sizeof(debounce_info));

  left.shift = -1;
  right.shift = 1;
  up.shift = 1;
  down.shift = -1;

  Serial.begin(9600);

  timer_conf();
  dma_conf();
  dma_start();
/*
  init_wave();
  EEPROM.read(0, (uint16*)&shift);
  EEPROM.read(500);  // // EEPROM for amp
  get_wave(shift);
*/
////////////////////////////////////////
 init_wave();
  EEPROM.read(0, (uint16*)&shift);
  EEPROM.get(500);  // // EEPROM for amp
  get_wave(shift);

////////////////////////////////////////
}

void loop() {
  process_key(digitalRead(phasep), &right);
  process_key(digitalRead(phasen), &left);
  process_key_amp(digitalRead(ampp), &up);
  process_key_amp(digitalRead(ampn), &down);
  delay(100);

}

void process_key(int val, struct debounce_info *k)
{
  switch (k->state)               //faza
  {
    case DEBOUNCE_IDLE:
      if (val == HIGH)
      {
        k->state = DEBOUNCE_ACTIVE;
        k->start = millis();
      }
      break;

    case DEBOUNCE_ACTIVE:
      if (val == HIGH)   ////////////
      {
        if (millis() - k->start > DEBOUNCE_DELAY)
        {
          shift += k->shift;
          Serial.println("increasing");
          Serial.println(shift);
          Serial.println(k->shift);
          get_wave(shift);

        }
      }
      else
        k->state = DEBOUNCE_IDLE;
      EEPROM.write(0, shift);    /////////
      Serial.println(shift);
      break;                 // faza
  }
}

void process_key_amp(int val, struct debounce_info *k)
{
  switch (k->state)
  {
    case DEBOUNCE_IDLE:
      if (val == HIGH)     ///////////
      {
        k->state = DEBOUNCE_ACTIVE;
        k->start = millis();
      }
      break;

    case DEBOUNCE_ACTIVE:
      if (val == HIGH)
      {
        if (millis() - k->start > DEBOUNCE_DELAY)
        {
          amp += (int)k->shift;
          get_wave(shift);
          //EEPROM.write(500, amp);
        }
      }
      else
        k->state = DEBOUNCE_IDLE; /////////////
      EEPROM.put(500, amp);
      break;
  }
}

Using library EEPROM in folder: C:\Users\OWNER\AppData\Local\Arduino15\packages*stm32duino*\hardware*STM32F1*\2018.1.3\libraries\EEPROM (legacy)

So you didn't think this super important detail was worth mentioning?

The STM32 EEPROMClass is quite a bit different from the AVR version (no get() & put()):

class EEPROMClass
{
public:
        EEPROMClass(void);

        uint16 init(void);
        uint16 init(uint32, uint32, uint32);

        uint16 format(void);

        uint16 erases(uint16 *);
        uint16 read (uint16 address);
        uint16 read (uint16 address, uint16 *data);
        uint16 write(uint16 address, uint16 data);
        uint16 count(uint16 *);
        uint16 maxcount(void);

        uint32 PageBase0;
        uint32 PageBase1;
        uint32 PageSize;
        uint16 Status;
private:
        FLASH_Status EE_ErasePage(uint32);

        uint16 EE_CheckPage(uint32, uint16);
        uint16 EE_CheckErasePage(uint32, uint16);
        uint16 EE_Format(void);
        uint32 EE_FindValidPage(void);
        uint16 EE_GetVariablesCount(uint32, uint16);
        uint16 EE_PageTransfer(uint32, uint32, uint16);
        uint16 EE_VerifyPageFullWriteVariable(uint16, uint16);
};

EDIT: Not sure that we have the same STM32 stuff, but it is still different from the AVR stuff.

You should declare a global const or define with the address to where you are storing (eg. #define EEPROM_ADDR 100). In "setup()" you must remove your "EEPROM.read" and use "EEPROM.get(EEPROM_ADDR, amp)". When storing use "EEPROM.put(EEPROM_ADDR, amp)".

A side note: It seems like you are writing to EEPROM quite often. You should avoid this since EEPROM has a very limited amount of write cycles (~100k) before it weares out.

EDIT: Seems like this post is useless within the context of this topic.

my changes and error, I know about 100 000.

“C:\Users\OWNER\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++” -c -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE -std=gnu++11 -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103c -DVECT_TAB_ADDR=0x8000000 -DERROR_LED_PORT=GPIOB -DERROR_LED_PIN=1 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10803 -DARDUINO_GENERIC_STM32F103C -DARDUINO_ARCH_STM32F1 -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ “-IC:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\system/libmaple” “-IC:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\system/libmaple/include” “-IC:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\system/libmaple/stm32f1/include” “-IC:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\system/libmaple/usb/stm32f1” “-IC:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\system/libmaple/usb/usb_lib” “-IC:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\cores\maple” “-IC:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\variants\generic_stm32f103c” “-IC:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\libraries\EEPROM” “C:\Users\OWNER\AppData\Local\Temp\arduino_build_27431\sketch\amplitude_not_equal.ino.cpp” -o “C:\Users\OWNER\AppData\Local\Temp\arduino_build_27431\sketch\amplitude_not_equal.ino.cpp.o”
C:\Users\OWNER\Desktop\start over 2\amplitude_not_equal\amplitude_not_equal.ino: In function ‘void setup()’:

amplitude_not_equal:147: error: ‘class EEPROMClass’ has no member named ‘get’

EEPROM.get(500, (uint16*)&amp);

^

amplitude_not_equal:180: error: ‘class EEPROMClass’ has no member named ‘get’

EEPROM.get(EEPROM_500, amp);

^

amplitude_not_equal:180: error: expected primary-expression before ‘,’ token

EEPROM.get(EEPROM_500, amp);

^

C:\Users\OWNER\Desktop\start over 2\amplitude_not_equal\amplitude_not_equal.ino: In function ‘void process_key_amp(int, debounce_info*)’:

amplitude_not_equal:253: error: ‘class EEPROMClass’ has no member named ‘put’

EEPROM.put(EEPROM_500, amp);

^

amplitude_not_equal:253: error: expected primary-expression before ‘,’ token

EEPROM.put(EEPROM_500, amp);

^

Using library EEPROM in folder: C:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\libraries\EEPROM (legacy)
exit status 1
‘class EEPROMClass’ has no member named ‘get’

#define EEPROM_500

////////////////////////////////////////
 init_wave();
  EEPROM.read(0, (uint16*)&shift);
  EEPROM.get(EEPROM_500, amp);
 // EEPROM.get(500);  // // EEPROM for amp
  get_wave(shift);

////////////////////////////////////////

  }
      else
        k->state = DEBOUNCE_IDLE; /////////////
        EEPROM.put(EEPROM_500, amp);
      //EEPROM.put(500, amp);
      break;
  }

One of your errors

Using library EEPROM in folder: C:\Users\OWNER\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2018.1.3\libraries\EEPROM (legacy)
exit status 1
'class EEPROMClass' has no member named 'get'

Did you read reply #5 ?

The STM32 EEPROMClass is quite a bit different from the AVR version (no get() & put()):

UKHeliBob:
]

Did you read reply #5 ?

Of course, some AVR programs I was able to modify for ARM, so I think it is possible to do in this case.

Of course,

But you seem to have taken no notice of it.

You cannot use functions that do not exist.

So I have to find a replacement AVR function for ARM.

I found a simple one, Paul’s suggestion is working !!!

int amp2=35;
int amp = 35;

val1[i] = 50 + amp2 * sin(stp * i);
      val2[i] = val1[i];

I found a simple one, Paul's suggestion is working !!!

Strange. Nobody named Paul has contributed to this thread.

And of course, saving a value in an array does not meet your requirement

How to make amplitude Channel 2 as is stored in EEPROM so, turn OFF/ON the power will not effect on amplitude Channel 1 ?

Paul is from LCD clear

ted:
Paul is from LCD clear

...and men are from Mars.

That is an option

Danois90:
You should declare a global const or define with the address to where you are storing (eg. #define EEPROM_ADDR 100). In "setup()" you must remove your "EEPROM.read" and use "EEPROM.get(EEPROM_ADDR, amp)". When storing use "EEPROM.put(EEPROM_ADDR, amp)".

A side note: It seems like you are writing to EEPROM quite often. You should avoid this since EEPROM has a very limited amount of write cycles (~100k) before it weares out.

EDIT: Seems like this post is useless within the context of this topic.

Thanks.
My solution is good for my specific application, yours is universal. I Have to find some examples to learn how your commands are working to figure out, how to work on ARM substitute.