Pages: [1]   Go Down
Author Topic: how to read serial communication every 200ms  (Read 581 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi i have a big code that makes a cycle on about 1 minute.


i want to make the code to run a fuction (for example void reading_rx()  ) that reads serial data every 200ms.

i know that one  solution is in to call the fuction many times in the code, but as i know there is a eventfuse that can do this work better.


can someone post here a (full) example code? becouse i dont know how event fuse works
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.arduino.cc/playground/Code/TimedAction

That is my solution for trigering events every X milliseconds.
See the example if you're interested! smiley
Logged

0
Offline Offline
God Member
*****
Karma: 2
Posts: 596
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Many "timed-action" libraries (your library, SimpleTimer (mine) and Time+TimeAlarm) are based on the "polling" concept: a function must be called in loop() at least once per ms, so it can check wether it's time to call a function.

If the op's cycle needs 1 minute to run, then none of the mentioned libraries can help.
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The title says every 200ms smiley
And, at least for my library, you can update the TimedAction at any rate you prefer, but that will also limit the presicion of the timing.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2883
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Be aware that at 9600 bps, a busy line will overflow the serial receiver buffer in 133ms.
Logged

Per Arduino ad Astra

0
Offline Offline
God Member
*****
Karma: 2
Posts: 596
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@AlphaBeta: you're right, my statement about the need to call the control routine every 1ms is wrong.
You have to call it at least every x ms if you want an action to be performed every x ms, or obviously you'll loose some "ticks".

If the op's routine needs 1 minute to run, then he can fire timed actions every minute, not sooner.
Logged

Pages: [1]   Go Up
Jump to: