Pulse conter with timer and EEPROM write.

Hi,

i am working on pulse counter with DG21 Indio board. On int 8 i set up flag and in timer (avdweb_SAMDtimer.h) routine every 0,5sek i am checking

if ( ( flag ) && (Indio.digitalRead(CH1) == LOW) ).

I do it in timer routine because i want to calculate pulses / hour. Everything working fine until i am trying to write to EEPROM  (I2C_eeprom.h) during this timer routine. It looks like that nothing is write to EEPROM. If i move this task to main loop its working fine. But in this situation after using function U8g2lib (example userInterfaceSelectionList) main thread stucks in this function and pulses are beeing omited.

So, how to create two threads one for menu, second for pulse counting.

Why there is a problem with writing to EEPROM during timer routine ?

Thanks

Artur

 

Artur
Artur
4
| 1 1 1
Asked on 11/15/18, 7:07 PM
0
vote
2485 Views

Hi, When the flag is true and your CH1 is low and then increase a static counter and set the flag to false. Then on a seperate timer (I would use the Real time clock and the Time.h library as its accurate to 1 second), then update the value of the counter to eeprom.

If you need more accuracy then use a hardware timer for your hour count, but dont write to eeprom in the timer routine, just set another flag and write to eeprom from the main loop. (you may need to disable the interupts before eeprom update and enable afterwards again if you are writing lots if data - but I would think if you are writing just a value it shoudl work okay?).

 

 

Shane van Jaarsveldt
Shane van Jaarsveldt
32
| 3 1 2
Answered on 12/3/18, 11:50 AM
0
vote

Hi Artur again,

Did you insert a timer of 1 ms after you have written to your EEPROM ? If you haven't, then you are in trouble. By the way, if your pulse frequency is too high, remember an EEPROM is functional up to a couple of huntdred thousand writes, which may amont to quite a short period of time in case you wrtite to it constantly.

Didier, DG2R

/ Hi Artur,

/ I tend to count rising (or lowering) fronts when counting rather than input states. This avoids unvoluntary repeats when your pulse / crosses a CPU scan. I guess it depends on the frequency of your pulses. If the IndIO D21G scan time is around 100 ms so it should / work correctly up to around 3 Hz of pulse frequency (have a look at shannon's theorem about sampling).

/ For higher frequencies you may have to use use interrupts.

/ Hope this helps,

/ Didier, DG2R

Didier DORGUIN
Didier DORGUIN
172
| 4 1 3
Answered on 11/15/18, 7:51 PM
0
vote

Hi Dider,

thank you for your answer. As i mentioned i use interrupt no.8 - this is Indio innterupt. After setting a flag in int 8 ISR,   i am checking in timer routine that :

if ( ( flag ) && (Indio.digitalRead(CH1) == LOW) ) to be sure that interrupt is from CH1. If there is a better way to do it, i am very excitet to hear about that :).

Thanks

Artur

Artur
Artur
4
| 1 1 1
Answered on 11/16/18, 9:42 AM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

52 follower(s)

Stats

Asked: 11/15/18, 7:07 PM
Seen: 2485 times
Last updated: 12/3/18, 11:50 AM