Newton's approximation - Benchmark based on Steve Curd Adruino IDE code for STM32 Nucleo F7 ARM M7 MCU's
main.cpp@0:11c8121e645d, 2017-07-02 (annotated)
- Committer:
- JovanEps
- Date:
- Sun Jul 02 17:31:48 2017 +0000
- Revision:
- 0:11c8121e645d
RC 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JovanEps | 0:11c8121e645d | 1 | #include "mbed.h" |
JovanEps | 0:11c8121e645d | 2 | //******************************************************** |
JovanEps | 0:11c8121e645d | 3 | //** ARM Cortex M7 MCU ****** |
JovanEps | 0:11c8121e645d | 4 | //** ST Nucleo-144 Stm32F746 and Stm32F767 MCU ****** |
JovanEps | 0:11c8121e645d | 5 | //** Newton's approximation - Benchmark based on ****** |
JovanEps | 0:11c8121e645d | 6 | //** Steve Curd Adruino IDE code ****** |
JovanEps | 0:11c8121e645d | 7 | //** Jovan Ivković - 2017. ****** |
JovanEps | 0:11c8121e645d | 8 | //** JovanEps (jovan.eps@gmail.com). ****** |
JovanEps | 0:11c8121e645d | 9 | //******************************************************** |
JovanEps | 0:11c8121e645d | 10 | |
JovanEps | 0:11c8121e645d | 11 | DigitalOut myled(LED1); |
JovanEps | 0:11c8121e645d | 12 | //DigitalOut PD13(PA_5); //introduce D13 pin-out |
JovanEps | 0:11c8121e645d | 13 | DigitalIn PD8(PF_12); //introduce D8 *-Clear port |
JovanEps | 0:11c8121e645d | 14 | Serial pc(USBTX, USBRX); |
JovanEps | 0:11c8121e645d | 15 | Timer timer; |
JovanEps | 0:11c8121e645d | 16 | |
JovanEps | 0:11c8121e645d | 17 | #define ITERATIONS 10000000L // number of iterations 100k-10M |
JovanEps | 0:11c8121e645d | 18 | #define FFLASH 1000000 // blink LED every 100k-1M iterations |
JovanEps | 0:11c8121e645d | 19 | |
JovanEps | 0:11c8121e645d | 20 | //#include <TM1638.h> // include the display library |
JovanEps | 0:11c8121e645d | 21 | |
JovanEps | 0:11c8121e645d | 22 | // TM1638 module(DIO, CLK, STB0) |
JovanEps | 0:11c8121e645d | 23 | //TM1638 module(8, 9, 7); |
JovanEps | 0:11c8121e645d | 24 | |
JovanEps | 0:11c8121e645d | 25 | //********************************* |
JovanEps | 0:11c8121e645d | 26 | //** MAIN block ** |
JovanEps | 0:11c8121e645d | 27 | //********************************* |
JovanEps | 0:11c8121e645d | 28 | int main() |
JovanEps | 0:11c8121e645d | 29 | { |
JovanEps | 0:11c8121e645d | 30 | while(true) { |
JovanEps | 0:11c8121e645d | 31 | unsigned long start, ttime; |
JovanEps | 0:11c8121e645d | 32 | unsigned long niter = ITERATIONS; |
JovanEps | 0:11c8121e645d | 33 | int LEDcounter = 0; |
JovanEps | 0:11c8121e645d | 34 | bool alternate = false; |
JovanEps | 0:11c8121e645d | 35 | long i, count = 0; |
JovanEps | 0:11c8121e645d | 36 | double x = 1.0; |
JovanEps | 0:11c8121e645d | 37 | double temp, pi = 1.0; |
JovanEps | 0:11c8121e645d | 38 | |
JovanEps | 0:11c8121e645d | 39 | pc.printf(" \n Beginning %d",niter ); |
JovanEps | 0:11c8121e645d | 40 | pc.printf(" \n iterations..."); |
JovanEps | 0:11c8121e645d | 41 | pc.printf("\n"); |
JovanEps | 0:11c8121e645d | 42 | |
JovanEps | 0:11c8121e645d | 43 | timer.start(); |
JovanEps | 0:11c8121e645d | 44 | start = timer.read_ms(); |
JovanEps | 0:11c8121e645d | 45 | |
JovanEps | 0:11c8121e645d | 46 | for ( i = 2; i < niter; i++) { |
JovanEps | 0:11c8121e645d | 47 | x *= -1.0; |
JovanEps | 0:11c8121e645d | 48 | pi += x / (2.0f * (float) i - 1.0f); |
JovanEps | 0:11c8121e645d | 49 | // /* |
JovanEps | 0:11c8121e645d | 50 | if (LEDcounter++ > FFLASH) { |
JovanEps | 0:11c8121e645d | 51 | LEDcounter = 0; |
JovanEps | 0:11c8121e645d | 52 | if (alternate) { |
JovanEps | 0:11c8121e645d | 53 | myled = 1; |
JovanEps | 0:11c8121e645d | 54 | alternate = false; |
JovanEps | 0:11c8121e645d | 55 | } else { |
JovanEps | 0:11c8121e645d | 56 | myled = 0; |
JovanEps | 0:11c8121e645d | 57 | alternate = true; |
JovanEps | 0:11c8121e645d | 58 | } |
JovanEps | 0:11c8121e645d | 59 | temp = (float) 40000000.0 * pi; |
JovanEps | 0:11c8121e645d | 60 | |
JovanEps | 0:11c8121e645d | 61 | //module.setDisplayToDecNumber( temp, 0x80); |
JovanEps | 0:11c8121e645d | 62 | } |
JovanEps | 0:11c8121e645d | 63 | //*/ |
JovanEps | 0:11c8121e645d | 64 | } |
JovanEps | 0:11c8121e645d | 65 | ttime = timer.read_ms() - start; |
JovanEps | 0:11c8121e645d | 66 | |
JovanEps | 0:11c8121e645d | 67 | pi = (double) pi * 4.0; |
JovanEps | 0:11c8121e645d | 68 | |
JovanEps | 0:11c8121e645d | 69 | pc.printf("# of trials = %d \n", niter); |
JovanEps | 0:11c8121e645d | 70 | pc.printf("\n\n"); |
JovanEps | 0:11c8121e645d | 71 | pc.printf("Estimate of pi = %6.10f 10 \n" , pi); |
JovanEps | 0:11c8121e645d | 72 | pc.printf("Time: %d ms \n", ttime); |
JovanEps | 0:11c8121e645d | 73 | printf("state: %d \n", alternate); |
JovanEps | 0:11c8121e645d | 74 | |
JovanEps | 0:11c8121e645d | 75 | timer.stop(); |
JovanEps | 0:11c8121e645d | 76 | wait(1); |
JovanEps | 0:11c8121e645d | 77 | } |
JovanEps | 0:11c8121e645d | 78 | } |