Hello
I am just trying to determine what the loading on my arduino processor currently is, as I want to know if I have enough 'cpu' time to do some more stuff.
Basically I have the following bit of code at the start of my loop, to capture the current time and compare it against the time of the last loop, so I can see the time per loop effectively.
unsigned long Time;
unsigned long PrevTime;
unsigned int ScanTime;
void loop()
{
PrevTime = Time;
Time = micros();
ScanTime = Time - PrevTime;
*/blah blah/*
}
I also have some LCD code, and some Keypad code, and also sending some data (Sine wave values at the moment) to the serial port at 9600 baud, every loop. The Sine Wave values are just for the sake of having data to send to the serial, this will be replaced with the data I talk about at the end of this speech!
What the scan time is telling me is it is taking approximately 30ms per loop.
I just wanted to run a few calculations I made by you to see if I am correct...
30 ms/loop = 0.03 seconds/loop
1 / 0.03 = 33.3 loops/second
16Mhz CPU = 16,000,000 'cycles'/second
16,000,000 / 33.3 = 480480.48 'cycles'/loop
That is quite a few...
The next calculation is how much data I am sending over the serial link.
I have it set on 9600 baud, which is 9600 bits/second.
Each loop of my sketch, I am writing up to 20 characters onto the serial port. Whether or not this is correct or not, im not sure... but 20 characters is 20 bytes, which is 160 bits.
I am currently running 33.3 loops/second, and therefore:
160 bits * 33.3 times second = 5328 bits/second
So in theory I am within my limits of 9600 baud. Is this correct?
If I was to halve my scan time however, by say taking out my LCD and the print statements to it, then my loops/second would increase... so say 15ms/loop now, which is 0.015 seconds/loop, which is 66.6 loops/second. So therefore 160 bits * 66.6 = 10666 bits/second.
So does that mean that 9600 baud will no longer cope with the amount of data I am sending it?
Is this how you calculate this all out?
What I want to add onto the project is 2 high speed pulse trains into the external interrupts. One of the pulse trains is going to be coming in at about 340 pulses per second.
Is this going to cope..?
Sorry for the long post, but hopefully someone will spend the time to read and point me in the right direction.
Thanks