1 | #include "altera_up_avalon_video_pixel_buffer_dma.h"
|
2 | #include "altera_up_avalon_video_character_buffer_with_dma.h"
|
3 | #include "sys/alt_stdio.h"
|
4 |
|
5 | #include "sys/altera_avalon_pio_regs.h"
|
6 | #include "sys/altera_avalon_jtag_uart_regs.h"
|
7 | #include "sys/altera_avalon_timer_regs.h"
|
8 |
|
9 | // === the fixed point macros ========================================
|
10 | typedef signed int fix16 ;
|
11 |
|
12 | #define fix2int16(a) ((int)((a)>>8))
|
13 | #define int2fix16(a) ((fix16)((a)<<8))
|
14 | #define float2fix16(a) ((fix16)((a)*65536.0)) // 2^16
|
15 |
|
16 | int main(void)
|
17 | {
|
18 |
|
19 | while(1){
|
20 |
|
21 | volatile int button_read;
|
22 | volatile int dummy_delay=32768;
|
23 |
|
24 | ///////////////////////////////// NEW CODE //////////////////////////////////
|
25 |
|
26 | //Prepare to load floating point input from serial console
|
27 | float input_float;
|
28 |
|
29 |
|
30 | //For each initial condition, ask the user to input a decimal value.
|
31 | printf("Enter kp ");
|
32 | scanf("%f", &input_float);
|
33 |
|
34 | //NIOS must convert that floating point value to fixed-point compatible with
|
35 | //the top-level hardware spring system.
|
36 | *(volatile int *)KP_BASE = input_float;
|
37 |
|
38 | //Do the same for the rest of the inputs.
|
39 | printf("Enter ki: ");
|
40 | scanf("%f", &input_float);
|
41 | *(volatile int *)KI_BASE = input_float;
|
42 |
|
43 | printf("Enter kd ");
|
44 | scanf("%f", &input_float);
|
45 | *(volatile int *)KD_BASE = input_float;
|
46 |
|
47 | ///////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
|
49 | alt_up_pixel_buffer_dma_dev *pixel_buffer_dev;
|
50 | alt_up_char_buffer_dev *char_buffer_dev;
|
51 |
|
52 | int vga_x, vga_y, clock_interval, clock_counter, initial_condition_set,x1_read_value, x1_read_value_print, x2_read_value, x2_read_value_print;
|
53 |
|
54 | int pid_out_value;
|
55 |
|
56 | ///////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
58 | /* used for drawing coordinates */
|
59 | int x1, y1, x2, y2, deltax_1, deltax_2, deltay_1, deltay_2, delay = 0;
|
60 |
|
61 | /* initialize the pixel buffer HAL */
|
62 | pixel_buffer_dev = alt_up_pixel_buffer_dma_open_dev ("/dev/VGA_Pixel_Buffer");
|
63 | if ( pixel_buffer_dev == NULL)
|
64 | alt_printf ("Error: could not open VGA pixel buffer device\n");
|
65 | else
|
66 | alt_printf ("Opened character VGA pixel buffer device\n");
|
67 | /* clear the graphics screen */
|
68 | alt_up_pixel_buffer_dma_clear_screen(pixel_buffer_dev, 0);
|
69 |
|
70 | vga_x=1;
|
71 |
|
72 | while(1){
|
73 |
|
74 | x1_read_value = *(volatile int*)PIO_X1_OUTPUT_INIT_7_BASE;
|
75 | x2_read_value = *(volatile int*)PIO_X2_OUTPUT_INIT_8_BASE;
|
76 |
|
77 | dummy_delay=1<<11;
|
78 | while(dummy_delay--){}
|
79 |
|
80 | vga_x++;
|
81 |
|
82 | x1_read_value_print = x1_read_value >> 7; //White Line
|
83 | x2_read_value_print = x2_read_value >> 7; // Brown Line
|
84 |
|
85 | ///// For debug only
|
86 | //printf ("raw_prox = %d \t median = %d \n",x1_read_value,x2_read_value);
|
87 |
|
88 | // Implementing filtering in Verilog itself
|
89 |
|
90 | alt_up_pixel_buffer_dma_draw_box(pixel_buffer_dev, vga_x, 480-x1_read_value_print - 13, vga_x, 480-x1_read_value_print - 13, 0xFFFF, 0);
|
91 |
|
92 | alt_up_pixel_buffer_dma_draw_box(pixel_buffer_dev, vga_x, 480-x2_read_value_print - 10, vga_x, 480-x2_read_value_print - 10, 0x8888, 0);
|
93 |
|
94 | alt_up_pixel_buffer_dma_draw_box(pixel_buffer_dev, vga_x, 480-(32767>>7) - 10, vga_x, 480-(32767>>7) - 10, 0x187F, 0);
|
95 |
|
96 | alt_up_pixel_buffer_dma_draw_box(pixel_buffer_dev, vga_x, 480-0 - 10, vga_x, 480-0 - 10, 0x49AF, 0);
|
97 |
|
98 | if (vga_x == 639){
|
99 | alt_up_pixel_buffer_dma_clear_screen(pixel_buffer_dev, 0);
|
100 | vga_x=0;
|
101 | }
|
102 |
|
103 | }
|
104 | }
|
105 | return 0;
|
106 | }
|