I have read the datasheet for the nRF52840.
Unfortunately, that didn't make me any smarter.
I get along better with Atmel's datasheets.
I have the problem that I do not understand the registers for the timers.
I would like to measure an incoming rectangular signal where I only measure the low pass. It comes from a flow meter.
Unfortunately, I don't know now whether I can do it with an interrupt counter or just count a timer.
And millis () seems a bit harder to me. Do you have any ideas?
I have experience with Atmel, the Atmega32A and Interrups, Registers, through another project.
But I don't know whether the measurement is correct, i.e. more of a hardware problem, or whether the Arduino's measurement is wrong.
The square wave signal is currently being made available by an Atmega32A for testing purposes and sent to the Arduino.
Before looking at the issue, may I suggest a few things.
When you post an example, reduce it to the bare minimum to show your issue. e.g., remove all TFT code, remove all dead code. This will allow others to play with your code and make suggestions. Most user likely do not have the same TFT as you have.
Program using two languages not three. Your English seems fine.
Spend more time picking variable and function names. Variable1 2 3 are not good variable names.
Use the Arduino variable naming conventions camelCase staring with lower case for variables and functions, CAPITAL_WITH_UNDERSCORE for constant values
Now to your issue. Can you provide some more information about the signal ( frequency, duty cycle including the range ) you are trying to capture and what resolution and update rate do you need? I am assuming the signal is digital and at the right voltage level.
It is just a recommendation. Write your code so it is easy to understand for other programmers. After not looking at your code for two months, you are one of the others. C/C++ is based on English. I am not a native English speaker.
I am a bit confused about the sensor signal. The ATmega is just for simulating a real flow sensor, right?
I understood you have a LOW interval that changes but the HIGH interval stays fixed. That seems weird. I do not want to reverse engineer your ATmega code and start with a wrong premise because I made a mistake.
What does the flow sensor signal look like?
I am asking because, the Arduino Nano 33 BLE is an expensive piece of hardware for the amount of code you have so far. Do you want to use BLE or anything else this chip has to offer? Because then the basic principle of your current code will not work.
A few more things I noted about your code.
I am not sure the following code is safe to use. Make Zeit_Signal_Verbrauch an unsigned long.
When you miss an interrupt, your code will break because it will start measuring the HIGH phase of your signal.
I would recommend giving interrupt handlers a special name. That will make it immediately clear for somebody reading the code. Some use ISR and the Common Microcontroller Software Interface Standard (CMSIS) from ARM recommends suffix _Handler in the name.
Good question! If you are not going to using BLE there are way better choices for your board. I suspect that a basic nano clone would be fine.
Why have you chosen the nano 33 BLE?
I don't think that you have answered these questions you were previously asked?
Can you provide some more information about the signal ( frequency, duty cycle including the range ) you are trying to capture and what resolution and update rate do you need?
ATmega is for simulating, right. This is the Flowmeter: https://www.conrad.de/ Datasheet Flowmeter
The Flowmeter generates 10,500 pulses per liter.
At max. (0.8l/min): 7.14 ms/Pulse
At min. (0.015l/min): 380.95ms/Pulse
I also could missunderstand my informations
My inital idea was to load the skretch via Bluetooth. But after buying and more investigation i realized, that is not possible with the 33 BLE. But in the Future, i want to change settings via app an transfer data to another Arduino. - The problem to not have an EEPROM is my next step to solve.
This will give you a good resolution when the flow rate is low. As the pulses get shorter the resolution will get lower because the timer get more inaccurate.
For higher flow rate you can inverse the measurement and just count pulses. Simply increment a counter in the ISR. In your main loop you would then read the counter variable in a regular interval and get the frequency. Here you get the inverse issue when the flow rate gets very low you get lower resolution.
In any case, if you want to use BLE later you should look into using the hardware timer. You will have the same two options.
It works perfectly. Thank you. Micro is the better idea.
I can't find the library to include KVStore in the Arduino IDE or Atmel Studio.
I prefer to work with Atmel Studio
Did anyone have a link. I couldn't find anything usefull at MbedOS.
It's ok for me. It doesn't need to be 1000% right.
I've read the datasheet of the nRF52840, but can't find usefull infos about the timer registers and the ISR. Or I don't understand the datasheet.
The Atmel-datasheets are more userfriendly in my eyes.
Did you have infos what Timer I have, need for BLE and can use for other tastks?
I would love to use the ISR for counting micro and not use mirco().
Did you have infos what Timer I have, need for BLE and can use for other tastks?
I would love to use the ISR for counting micro and not use mirco().
Regarding Timers and the Nano33 BLE there are two libraries you can use. Both are available through the library manager.
NRF52_MBED_TimerInterrupt
by Khoi Hoang v1.2.1
TimerInterrupt_Generic
by Khoi Hoang v1.7.0
I can't find the library to include KVStore in the Arduino IDE or Atmel Studio.
I prefer to work with Atmel Studio
Did anyone have a link. I couldn't find anything usefull at MbedOS.
Here is a simplified example of KV store. There is no library that I am aware of.
//https://os.mbed.com/docs/mbed-os/v6.12/apis/kvstore.html
//KVStore. TDBStore - Default implementation of the KVStore API. It provides static wear-leveling and quick access for when you have a small number of KV pairs.
//https://os.mbed.com/docs/mbed-os/v6.12/apis/data-architecture.html
#include "KVStore.h"
#include "kvstore_global_api.h"
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("--- Mbed OS KVStore Simplified example--- ");
/* Start By Resetting the KV Storage */
Serial.println("kv_reset");
kv_reset("/kv/");//comment out when retreiving saved data
Serial.println();
const char* const Key1 = "store_cString";
const char* const Key2 = "store_longArray";
const char* const Key3 = "store_Struct";
/* Set First Key/Value pair*/
const char* const cStringToStore = "Hello World/Goodnight Moon";//const pointer to constant string
Serial.print("kv_set key: ");
Serial.println(Key1);
kv_set(Key1, cStringToStore, strlen(cStringToStore), 0); //0 for flags?
/* Read the KV Pair you've just set */
char Key1Out[strlen(cStringToStore) + 1] = "";
memset(Key1Out, '\0', strlen(cStringToStore) + 1); //clear and null terminate
kv_get(Key1, Key1Out, strlen(cStringToStore) + 1 , 0);
Serial.print("kv_get key: ");
Serial.println(Key1);
Serial.print("kv_get key Value: ");
Serial.println(Key1Out);
Serial.println();
/* Set Second Key/Value pair*/
uint32_t km[3];
km[0] = 123456789;
km[1] = 234567891;
km[2] = 345678912;
Serial.print("kv_set key: ");
Serial.println(Key2);
kv_set(Key2, (uint8_t*)&km, sizeof(km), 0);
/* Read the KV Pair you've just set */
uint32_t kmOut[3];
kmOut[0] = 0;
kmOut[1] = 0;
kmOut[2] = 0;
Serial.print("kv_get key: ");
Serial.println(Key2);
kv_get(Key2, (byte*)&kmOut, sizeof(kmOut), 0);
Serial.print("kv_get key Value: ");
for (byte i = 0; i < 3; i++)
{
Serial.print(kmOut[i]);
if (i != 2)
Serial.print(',');
}
Serial.println();
Serial.println();
/* Set Third Key/Value pair*/
typedef struct {
unsigned long timeStamp;
float accel;
char pres[4];
} structData;
structData dataSaved;
structData dataRetreived;
dataSaved.timeStamp = 445566;
dataSaved.accel = 1.23;
strcpy(dataSaved.pres, "789");
dataRetreived.timeStamp = 0;
dataRetreived.accel = 0;
strcpy(dataRetreived.pres, "---");
Serial.print("kv_set key: ");
Serial.println(Key3);
kv_set(Key3, (uint8_t*)&dataSaved, sizeof(dataSaved), 0);
Serial.print("kv_get key: ");
Serial.println(Key3);
kv_get(Key3, (byte*)&dataRetreived, sizeof(dataRetreived), 0);
Serial.print("kv_get key Value: ");
Serial.print(dataRetreived.timeStamp);
Serial.print(',');
Serial.print(dataRetreived.accel);
Serial.print(',');
Serial.print(dataRetreived.pres);
Serial.println();
/* Finally, reset will format kvstore and remove All Keys (including write-once keys) */
//Serial.println("kv_reset");
//kv_reset("/kv/");
}
void loop() {}
It's to simple for me. I don't understand how to store and get my Values.
I think it's a declaration like the Atmel-EEPROM. But how can I fix the savepoint.
This is to hard for me to translate
But it's not what the programm want and I not understand
The syntax for set is (const char *key, const void *buffer, size_t size, uint32_t create_flags)
KVStore is using the concept of Key/Value pairs, and not a storage address. All the internal address management is taken care of by the KVStore application.
The Key needs to be a character array name. I think the name is limited to 16 bytes. In your case, the Key might be "TankCapMax".
The stored value might be unsigned 16 bit integer maxAmount. It needs to be broken into bytes for storage and retreival.
//https://os.mbed.com/docs/mbed-os/v6.12/apis/kvstore.html
//KVStore. TDBStore - Default implementation of the KVStore API. It provides static wear-leveling and quick access for when you have a small number of KV pairs.
//https://os.mbed.com/docs/mbed-os/v6.12/apis/data-architecture.html
#include "KVStore.h"
#include "kvstore_global_api.h"
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("--- Mbed OS KVStore Simplified example--- ");
/* Start By Resetting the KV Storage */
Serial.println("kv_reset");
kv_reset("/kv/");//comment out when retreiving saved data
Serial.println();
uint16_t maxAmountStored = 1234;
uint16_t maxAmountReadBack = 0;
kv_set("TankCapMax", (uint8_t*)&maxAmountStored, sizeof(maxAmountStored), 0);
kv_get("TankCapMax", (uint8_t*)&maxAmountReadBack, sizeof(maxAmountReadBack), 0);
Serial.print("max amount = ");
Serial.println(maxAmountReadBack);
/* Finally, reset will format kvstore and remove All Keys (including write-once keys) */
//Serial.println("kv_reset");
//kv_reset("/kv/");
}
void loop() {}
Now I have a Value-problem, i don't understand:
In my case "State_Display" is always 1 although Total_Fuel (5500) is above RESERVE_WARNUNG_1 (1000). What is the problem?