This is a small program we use to see how long something takes. It runs the code in the while loop a lot of times and prints out how many us it took. Then this can be divided by the number of iterations to find the time/clock cycles for each iteration.
main.cpp@0:cff63309a8af, 2013-07-08 (annotated)
- Committer:
- avbotz
- Date:
- Mon Jul 08 03:58:56 2013 +0000
- Revision:
- 0:cff63309a8af
Initial commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
avbotz | 0:cff63309a8af | 1 | #include "mbed.h" |
avbotz | 0:cff63309a8af | 2 | #include "dsp.h" |
avbotz | 0:cff63309a8af | 3 | |
avbotz | 0:cff63309a8af | 4 | Serial pc(USBTX, USBRX); |
avbotz | 0:cff63309a8af | 5 | DigitalOut myled(LED1); |
avbotz | 0:cff63309a8af | 6 | Timer tim; |
avbotz | 0:cff63309a8af | 7 | |
avbotz | 0:cff63309a8af | 8 | int main() { |
avbotz | 0:cff63309a8af | 9 | unsigned int i = 0; |
avbotz | 0:cff63309a8af | 10 | |
avbotz | 0:cff63309a8af | 11 | q15_t lad[5], ref[6]; |
avbotz | 0:cff63309a8af | 12 | q15_t state[1029], in[1024], out[1024]; |
avbotz | 0:cff63309a8af | 13 | // this loop takes 4 assembly instructions to run per cycle |
avbotz | 0:cff63309a8af | 14 | // http://www.wolframalpha.com/input/?i=%282731+us%2F65536%29%2F%281%2F24000000Hz%29 |
avbotz | 0:cff63309a8af | 15 | arm_iir_lattice_instance_q15 filter = {5, state, ref, lad}; |
avbotz | 0:cff63309a8af | 16 | tim.start(); |
avbotz | 0:cff63309a8af | 17 | while (i<100) |
avbotz | 0:cff63309a8af | 18 | { |
avbotz | 0:cff63309a8af | 19 | arm_iir_lattice_q15(&filter, in, out, 1024); |
avbotz | 0:cff63309a8af | 20 | i++; |
avbotz | 0:cff63309a8af | 21 | } |
avbotz | 0:cff63309a8af | 22 | tim.stop(); |
avbotz | 0:cff63309a8af | 23 | pc.printf("%d us\n\r",tim.read_us()); |
avbotz | 0:cff63309a8af | 24 | } |
avbotz | 0:cff63309a8af | 25 | //mbed LPC1768 runs at 96 MHz |
avbotz | 0:cff63309a8af | 26 | //2731 us=65536 cycles |