Bit-banging - Port (pin) setting and pattern generation Speed - Benchmark. Measure internal port (pattern) setting time and can preset 10bit pattern for 1k runs for external measures.
main.cpp@11:de680c2510a6, 2017-01-04 (annotated)
- Committer:
- JovanEps
- Date:
- Wed Jan 04 16:33:24 2017 +0000
- Revision:
- 11:de680c2510a6
- Parent:
- 10:51adb7641cd7
Final version 1.0.1
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| screamer | 0:005629fe3609 | 1 | #include "mbed.h" |
| JovanEps | 6:64a3bea8be86 | 2 | //******************************************************** |
| JovanEps | 6:64a3bea8be86 | 3 | //** Nucleo-144 Stm32F746 and Stm32F767 bitbanging ****** |
| JovanEps | 7:13ae8d34cc97 | 4 | //** Port setting and pattern generation ****** |
| JovanEps | 7:13ae8d34cc97 | 5 | //** Speed - Benchmark ****** |
| JovanEps | 7:13ae8d34cc97 | 6 | //** Jovan Ivković - 2016. ****** |
| JovanEps | 7:13ae8d34cc97 | 7 | //** JovanEps (jovan.eps@gmail.com). ****** |
| JovanEps | 6:64a3bea8be86 | 8 | //******************************************************** |
| JovanEps | 7:13ae8d34cc97 | 9 | |
| screamer | 0:005629fe3609 | 10 | DigitalOut myled(LED1); |
| JovanEps | 5:64511b302803 | 11 | DigitalOut PD7(PF_13); |
| JovanEps | 7:13ae8d34cc97 | 12 | DigitalOut PD5(PE_11); //introduce D5 pin-out it ping faster :) |
| JovanEps | 6:64a3bea8be86 | 13 | DigitalOut PD13(PA_5); //introduce D13 pin-out |
| JovanEps | 6:64a3bea8be86 | 14 | Serial pc(USBTX, USBRX); |
| JovanEps | 7:13ae8d34cc97 | 15 | Timer timer; |
| screamer | 0:005629fe3609 | 16 | |
| JovanEps | 7:13ae8d34cc97 | 17 | void Pinging() |
| JovanEps | 7:13ae8d34cc97 | 18 | { |
| JovanEps | 10:51adb7641cd7 | 19 | int i, vreme = 0, loop_vreme=0, noop=0; |
| JovanEps | 7:13ae8d34cc97 | 20 | while(1) { |
| JovanEps | 7:13ae8d34cc97 | 21 | // Pattern and port setting speed benchmark |
| JovanEps | 7:13ae8d34cc97 | 22 | timer.start(); |
| JovanEps | 11:de680c2510a6 | 23 | // Measure loop and value setting time for 1k runs |
| JovanEps | 10:51adb7641cd7 | 24 | loop_vreme = timer.read_us(); |
| JovanEps | 10:51adb7641cd7 | 25 | for ( i = 0; i <= 999; i++ ) { |
| JovanEps | 11:de680c2510a6 | 26 | noop = i; |
| JovanEps | 10:51adb7641cd7 | 27 | } |
| JovanEps | 10:51adb7641cd7 | 28 | // ----- |
| JovanEps | 10:51adb7641cd7 | 29 | loop_vreme = timer.read_us() - loop_vreme; |
| JovanEps | 10:51adb7641cd7 | 30 | timer.reset(); |
| JovanEps | 11:de680c2510a6 | 31 | // Measure 10 bit sequence pattern |
| JovanEps | 7:13ae8d34cc97 | 32 | vreme = timer.read_us(); |
| JovanEps | 10:51adb7641cd7 | 33 | for ( i = 0; i <= 999; i++ ) { |
| JovanEps | 11:de680c2510a6 | 34 | PD5 = 1; // D5 go low 1 go LOW in next 69..75ns as Tf propagates signal on osciloscope |
| JovanEps | 7:13ae8d34cc97 | 35 | PD5 = 1; // D5 go low 2 |
| JovanEps | 7:13ae8d34cc97 | 36 | PD5 = 1; // D5 go low 3 |
| JovanEps | 7:13ae8d34cc97 | 37 | PD5 = 0; // D5 go inv-high on SN74vhc14 - >1.6..2.4V < 1.75ns |
| JovanEps | 7:13ae8d34cc97 | 38 | PD5 = 1; // D5 go low 5 |
| JovanEps | 7:13ae8d34cc97 | 39 | PD5 = 1; // D5 go low 6 |
| JovanEps | 7:13ae8d34cc97 | 40 | PD5 = 1; // D5 go low 7 |
| JovanEps | 7:13ae8d34cc97 | 41 | PD5 = 1; // D5 go low 8 |
| JovanEps | 7:13ae8d34cc97 | 42 | PD5 = 1; // D5 go low 9 |
| JovanEps | 7:13ae8d34cc97 | 43 | PD5 = 1; // D5 go low 10 |
| JovanEps | 7:13ae8d34cc97 | 44 | } |
| JovanEps | 7:13ae8d34cc97 | 45 | vreme = timer.read_us() - vreme; |
| JovanEps | 7:13ae8d34cc97 | 46 | wait_us(0.2); |
| JovanEps | 10:51adb7641cd7 | 47 | pc.printf("Port set time (single)... %6.2f ns \t tested on for: %d runs \n", ( float ) ( vreme - loop_vreme ) / 10, i * 10 ); //1000x10=10k sets of PD5 div 10 for ns |
| JovanEps | 11:de680c2510a6 | 48 | pc.printf("\n %d \n\n", noop+1); |
| JovanEps | 7:13ae8d34cc97 | 49 | timer.stop(); |
| JovanEps | 7:13ae8d34cc97 | 50 | |
| JovanEps | 7:13ae8d34cc97 | 51 | /* // Alternative |
| JovanEps | 7:13ae8d34cc97 | 52 | while(1) { |
| JovanEps | 6:64a3bea8be86 | 53 | PD5 = 0; // D5 go low 1 |
| JovanEps | 6:64a3bea8be86 | 54 | PD5 = 0; // D5 go low 2 |
| JovanEps | 6:64a3bea8be86 | 55 | PD5 = 0; // D5 go low 3 |
| JovanEps | 7:13ae8d34cc97 | 56 | PD5 = 1; // D5 go inv-low on 74vhc14 - <0.6v..0.9V < 1.6ns |
| JovanEps | 6:64a3bea8be86 | 57 | PD5 = 0; // D5 go low 5 |
| JovanEps | 6:64a3bea8be86 | 58 | PD5 = 0; // D5 go low 6 |
| JovanEps | 6:64a3bea8be86 | 59 | PD5 = 0; // D5 go low 7 |
| JovanEps | 6:64a3bea8be86 | 60 | PD5 = 0; // D5 go low 8 |
| JovanEps | 6:64a3bea8be86 | 61 | PD5 = 0; // D5 go low 9 |
| JovanEps | 6:64a3bea8be86 | 62 | PD5 = 0; // D5 go low 10 |
| JovanEps | 7:13ae8d34cc97 | 63 | wait_us(0.3); |
| JovanEps | 7:13ae8d34cc97 | 64 | */ |
| JovanEps | 7:13ae8d34cc97 | 65 | //pc.printf("\n"); |
| JovanEps | 6:64a3bea8be86 | 66 | } |
| JovanEps | 7:13ae8d34cc97 | 67 | } |
| JovanEps | 7:13ae8d34cc97 | 68 | |
| JovanEps | 7:13ae8d34cc97 | 69 | int main() |
| JovanEps | 7:13ae8d34cc97 | 70 | { |
| JovanEps | 5:64511b302803 | 71 | myled = 1; // LED is ON - working |
| JovanEps | 6:64a3bea8be86 | 72 | pc.baud(115200); |
| JovanEps | 7:13ae8d34cc97 | 73 | //pc.baud(921600); // Max garanted UART/seriall speed |
| JovanEps | 7:13ae8d34cc97 | 74 | pc.printf("Starting...\n"); |
| JovanEps | 7:13ae8d34cc97 | 75 | wait(0.2); // 200 ms |
| JovanEps | 7:13ae8d34cc97 | 76 | |
| JovanEps | 7:13ae8d34cc97 | 77 | //NVIC_DisableIRQ(XXX); // Disable NVIC interrupt; |
| JovanEps | 10:51adb7641cd7 | 78 | Pinging(); //Call of Pinging methode |
| JovanEps | 10:51adb7641cd7 | 79 | |
| JovanEps | 6:64a3bea8be86 | 80 | /* |
| screamer | 0:005629fe3609 | 81 | while(1) { |
| JovanEps | 11:de680c2510a6 | 82 | // PD7 = 1; // D7 go high in Tr ~69..75ns |
| JovanEps | 7:13ae8d34cc97 | 83 | //PD13 = 1; // D13 go high has delay of |
| JovanEps | 6:64a3bea8be86 | 84 | // myled = 1; |
| JovanEps | 7:13ae8d34cc97 | 85 | |
| JovanEps | 6:64a3bea8be86 | 86 | PD5 = 0; // D5 go high |
| JovanEps | 6:64a3bea8be86 | 87 | //wait(0); // 1ns - exclude, we need as fast as we can get |
| JovanEps | 11:de680c2510a6 | 88 | // PD7 = 0; // D7 go low in next 69..74ns |
| JovanEps | 7:13ae8d34cc97 | 89 | //PD13 = 0; // D13 go high |
| JovanEps | 6:64a3bea8be86 | 90 | // PD7 = 1; |
| JovanEps | 6:64a3bea8be86 | 91 | //PD13 = 1; // D13 go high |
| JovanEps | 6:64a3bea8be86 | 92 | PD5 = 0; |
| JovanEps | 6:64a3bea8be86 | 93 | // PD13 = 0; // D13 go high |
| JovanEps | 6:64a3bea8be86 | 94 | //myled = 0; |
| JovanEps | 6:64a3bea8be86 | 95 | PD5 = 0; // D5 go low |
| JovanEps | 6:64a3bea8be86 | 96 | PD5 = 1; // D5 go inv-high on 74vhc14 - 1v |
| JovanEps | 6:64a3bea8be86 | 97 | PD5 = 0; // D5 go low |
| JovanEps | 6:64a3bea8be86 | 98 | PD5 = 1; // D5 go inv-high on 74vhc14 -2v |
| JovanEps | 6:64a3bea8be86 | 99 | PD5 = 0; // D5 go low 2v |
| JovanEps | 6:64a3bea8be86 | 100 | PD5 = 1; // D5 go inv-high on 74vhc14 - 2v |
| JovanEps | 6:64a3bea8be86 | 101 | PD5 = 0; // D5 go low 2v |
| JovanEps | 6:64a3bea8be86 | 102 | PD5 = 1; // D5 go inv-high on 74vhc14 - 3v |
| JovanEps | 6:64a3bea8be86 | 103 | PD5 = 0; // D5 go low 3v |
| JovanEps | 6:64a3bea8be86 | 104 | //v4 111010101010101 4-low lead and 6-inv-peek |
| JovanEps | 6:64a3bea8be86 | 105 | PD5 = 1; // D5 go inv-high on 74vhc14 - 4v |
| JovanEps | 6:64a3bea8be86 | 106 | PD5 = 0; // D5 go low 4v |
| JovanEps | 6:64a3bea8be86 | 107 | PD5 = 1; // D5 go inv-high on 74vhc14 - 4v |
| JovanEps | 6:64a3bea8be86 | 108 | PD5 = 0; // D5 go low 4v |
| JovanEps | 6:64a3bea8be86 | 109 | //wait(0);// 1nsec - exclude, we need as fast as we can get |
| JovanEps | 7:13ae8d34cc97 | 110 | |
| JovanEps | 7:13ae8d34cc97 | 111 | } |
| JovanEps | 7:13ae8d34cc97 | 112 | */ |
| screamer | 0:005629fe3609 | 113 | } |