Arduino 16 Megahertz, how fast is my program running? - arduino

So, in theory how many times per second will the loop function be executed?
Can this be calculated based on the Megahertz? Arduino runs at 16 Megahertz

As Gerald said, you cannot simply take the clock frequency and calculate the loop method's iterations per second, some functions take long, some dont, what about delay(1000) and conditionals?
If your program needs to know how many times the loop is happening per second you can use the millis and micros methods. For example you can count the amount of times the loop has looped and save every second by monitoring millis or micros.

Related

Arduino Lightbulb Control

I am completely new to arduinos, and I am trying to run a lightbulb-style apparatus off of an arduino uno, and I need it to only operate on a certain time interval that I can adjust according to the situation. I believe that there is an internal time function in the arduino that counts in milliseconds. All i need it to do is turn on after a set amount of time, and then turn off after about a minute. How would I go about setting up the code for this?
You can use the millis() function to get the current arduino operational time in milliseconds. Then compare it in the next loop(). You probably don't care what the real time is, just the relative time since the last time you checked or did something. You can create a variable to store the last event time and compare the current time to that.
Be aware that millis() may be quite large if your program runs for a long time so you should use an unsigned long type, otherwise the value may roll over the top bit and become interpreted as a negative number (this is a common problem).

openCL : No. of iterations in profiling API

Trying to use clGetEventProfilingInfo for timing my kernels.
Is there any facility to give no. of iterations before which the values of start time and end time are reported?
If the kernel is run only once then , of ourse it has lots of over heads associated with it. So to get the best timing we should run the kernel several times and take the average time.
Do we have such a parameter in profiling using API? (We do have such parameters when we use third party software Tools for profiling)
The clGetEventProfilingInfo function will return profiling information for a single event, which corresponds to a single enqueued command. There is no built-in mechanism to automatically report information across a number of calls; you'll have to code that yourself.
It's pretty straightforward to do - just query the start and end times for each event you care about and add them up. If you are only running a single kernel (in a loop), then you could just use a wall-clock timer (with clFinish before you start and stop timing), or take the difference between the time the first event started and the last event finished.

Single-cycle vs a pipelined approach

I understand that single-cycle programs are not very efficient. One reason is because not all instructions are equal in length, but in a single-cycle program, all instructions are completed in the same length of time.
In pipeline, throughput is increased, which means the time between one output and the next will be shorter than in a single-cycle implementation after you reach a certain point. But then can you say that instructions in a pipelined approach take the same amount of time (going from IF/Instruction Fetch to WB/Writeback)? Or is this the wrong conclusion?
See all instructions in a single cycle non pipelined structure do not necessarily take same amount of time rather the next instruction to be executed after an instruction can not start until the next clock cycle ,current instruction may complete before the current cycle because cycle length is determined by the longest instruction.e.g add register completes before load in a RISC.
Now in a pipelined structure processor is
multistage with register to store and propogate the state of processor.Now basically on pipelined processor we save time by overlapping two instructionss' substages.hence even though individually the length of instruction is increased but overall time has reduced.Now see every instruction may not go through all the stages eg load and add again
So overall latency for each instruction will consist of all the stages but its execution may have had taken less number of cycles
So you can say that latency of each instruction is same but not the execution time or cycles consumed

Methods for detecting liquid drops with phototransistor

ECE people: I have a simple circuit with an LED pointing at a phototransistor. There is a tube in between them that drops of liquid will drip through at random times. I am reading the voltage with an Arduino at the emitter as it drops when the LED is occluded.
Non-ECE people: I am reading in near constant values every time through the Arduino loop. Every once in a while this value may change for some unknown number of loops. I want to increment a counter every time this happens and avoid multiple counts.
I have tried a few methods of my own (e.g. averages last some number of values and checking for different averages) but they seem to be pretty unstable. I'm not an expert at signal processing or anything, but I was wondering what some good methods/algorithms would be for this kind of thing. Any help would be appreciated. Thanks!
This a a short function to update the count of drops detected till now.
int UpdateCount (int current, int old, int count) // current is current value of phototransisor, old is the old value
if ((current==1)&(old==0)){
return count count+1
}
}
This function takes in "filtered" current and old values of the phototransistor and based on the values updates the count.
To implement a low pass filter, refer to low-pass-filter on wiki (http://en.wikipedia.org/wiki/Low-pass_filter). You will get an expression which you can easily code.
I believe these two sub-solution on integration solve your problem.

How to intrepret values of the ASP.NET Requests/sec performance counter?

If I monitor ASP.NET Requests/sec performance counter every N seconds, how should I interpret the values? Is it number of requests processed during sample interval divided by N? or is it current requests/sec regardless the sample interval?
It is dependent upon your N number of seconds value. Which coincidentally is also why the performance counter will always read 0 on its first nextValue() after being initialized. It makes all of its calculations relatively from the last point at which you called nextValue().
You may also want to beware of calling your counters nextValue() function at intervals less than a second as it can tend to produce some very outlandish outlier results. For my uses, calling the function every 5 seconds provides a good balance between up to date information, and smooth average.

Resources