How to use Timer1 library and intterupt Arduino1 + ethSchield???
hi everyone,
in project must use arduino1 , ethernet shield send data server.
pseudocode of first implementation:
every 10 seconds arduino send data server.
these version works, after several hours module freezes , not send data server.
-there isnt serial.print in isr
-i declared "volatile" each variable used in isr
-the isr void
at these version uploaded blinking led in loop debug arduino freeze.
during freeze led stop blinking , remains off
then try change firmware in tjese way:
-i removed timer1 , isr
-every 10 second arduino send data
the latest version freeze arduino approximately after 1 day!!!
however, dont understand problem.
i used binked led before delay in loop debug freeze.
during freeze:
-the led turned off
-in eth schield led pwd, link, 100m, fulld, coll on; rx , tx bink every 8/10 seconds
-arduino ide me:
sketch uses 15,592 bytes (48%) of program storage space. maximum 32,256 bytes.
global variables use 770 bytes (37%) of dynamic memory, leaving 1,278 bytes local variables. maximum is 2,048 bytes.
-furthermore used #include <memoryfree.h> study arduino memory usage , result constant during tests
i not understand how debug freeze
could me?
sorry english
in project must use arduino1 , ethernet shield send data server.
pseudocode of first implementation:
every 10 seconds arduino send data server.
these version works, after several hours module freezes , not send data server.
-there isnt serial.print in isr
-i declared "volatile" each variable used in isr
-the isr void
code: [select]
#include <timerone.h>
#include <ethernet.h>
#define pulse_port 2
byte mac[] = { mac };
ipaddress ip(arduinoip);
ipaddress server(serverip);
ethernetclient client;
volatile int pulses;
string request = "";
void setup()
{
serial.begin(9600);
if (ethernet.begin(mac) == 0)
{
serial.println("failed configure ethernet using dhcp");
ethernet.begin(mac, ip);
}
//set timer of length 10000000 microseconds = 10 seconds
timer1.initialize(10000000);
//attach service routine here
timer1.attachinterrupt( timerisr );
attachinterrupt(digitalpintointerrupt(pulse_port), read_pulse, falling);
}
void loop()
{
// nothing
}
void timerisr()
{
//connect server
int connectionresult = client.connect(server, 80);
if (connectionresult == 1)
{
request += "get ";
request += "fill request...":
client.println(request + " http/1.1");
client.println("host: iparduino");
client.println();
client.stop();
request = "";
}
else
{
pulses = 0;
client.stop();
}
}
void read_pulse()
{
// digitalread() of pulse_port , enhance variable pulses
}
at these version uploaded blinking led in loop debug arduino freeze.
code: [select]
#define is_alive 8
void loop()
{
digitalwrite(is_alive, high);
delay(1000);
digitalwrite(is_alive, low);
delay(1000);
}
during freeze led stop blinking , remains off
then try change firmware in tjese way:
-i removed timer1 , isr
-every 10 second arduino send data
code: [select]
#include <timerone.h>
#include <ethernet.h>
#define getmac string(string(mac[0], hex) + ":" + string(mac[1], hex) + ":" + string(mac[2], hex) + ":" + string(mac[3], hex)+ ":" + string(mac[4], hex) + ":" + string(mac[5], hex))
#define pulse_port 2
byte mac[] = {macarduino};
ipaddress ip(idarduino);
ipaddress server(ipserver);
ethernetclient client;
int packagenumber = 0;
int time_scale;
int watt_scale;
volatile int pulse_input;
volatile int pulses;
volatile int totalpulses;
string request = "";
int interrcount = 0;
void setup()
{
serial.begin(9600);
time_scale = 1;
watt_scale = 1;
if (ethernet.begin(mac) == 0)
{
serial.println("failed configure ethernet using dhcp");
ethernet.begin(mac, ip);
}
attachinterrupt(digitalpintointerrupt(pulse_port), read_pulse, falling);
}
void loop()
{
delay(1000);
interrcount++;
if ( interrcount == 10 )
{
int connectionresult = client.connect(server, 80);
if (connectionresult == 1)
{
request += "get ";
request += "fill request...with pulse , totalpulses value (in url format)";
client.println(request + " http/1.1");
client.println("host: iparduino");
client.println();
client.stop();
request = "";
}
interrcount=0;
}
}
// these function counts button push on custom module attached eth shield
// while (i--); --> tto avoid close input
// pulse_port pin n2
void read_pulse()
{
volatile int = 5;
while (i--);
pulse_input = digitalread(pulse_port);
if (pulse_input == low)
{
pulses++;
totalpulses++;
pulse_input = digitalread(pulse_port);
while (pulse_input == low)
{
pulse_input = digitalread(pulse_port);
}
}
}
the latest version freeze arduino approximately after 1 day!!!
however, dont understand problem.
i used binked led before delay in loop debug freeze.
during freeze:
-the led turned off
-in eth schield led pwd, link, 100m, fulld, coll on; rx , tx bink every 8/10 seconds
-arduino ide me:
sketch uses 15,592 bytes (48%) of program storage space. maximum 32,256 bytes.
global variables use 770 bytes (37%) of dynamic memory, leaving 1,278 bytes local variables. maximum is 2,048 bytes.
-furthermore used #include <memoryfree.h> study arduino memory usage , result constant during tests
i not understand how debug freeze
could me?
sorry english
quote
could me?first, lose timer interrupt. timer interrupts fine things need happen every many milliseconds. not appropriate things need happen every 10 minutes.
second, lose string class. there nothing string class c-style strings can't do. thing dynamic memory allocation (over , over). if largest allocation succeeds, static array of same size possible. so, use one.
after make changes, let know how long software runs before crashing.
Arduino Forum > Using Arduino > Programming Questions > How to use Timer1 library and intterupt Arduino1 + ethSchield???
arduino
Comments
Post a Comment