untested median filter#1
Draft
DonnyC123 wants to merge 11 commits into
Draft
Conversation
DonnyC123
commented
Feb 2, 2026
| pixel_t input_buffer_q [PIXELS_NEEDED- 1 : 0]; | ||
| pixel_t input_buffer_d [PIXELS_NEEDED- 1 : 0]; | ||
| logic [$clog2(PIXELS_NEEDED) - 1 : 0] pixel_ins_counter_q, pixel_ins_counter_d; | ||
| logic [$clog2(IMAGE_LEN) - 1 : 0] calculate_counter_q, calculate_counter_d; |
Owner
Author
There was a problem hiding this comment.
Remove spaces here between - 1 : 0, etc
DonnyC123
commented
Feb 2, 2026
| pixel_t input_buffer_d [PIXELS_NEEDED- 1 : 0]; | ||
| logic [$clog2(PIXELS_NEEDED) - 1 : 0] pixel_ins_counter_q, pixel_ins_counter_d; | ||
| logic [$clog2(IMAGE_LEN) - 1 : 0] calculate_counter_q, calculate_counter_d; | ||
| logic [$clog2(IMAGE_HEIGHT) - 1 : 0] current_row_q, current_row_d; |
DonnyC123
commented
Feb 2, 2026
| pixel_ins_counter_q <= '0; | ||
| input_buffer_q <= '0; | ||
| calculate_counter_q <= '0; | ||
| current_row_q <= '0; |
DonnyC123
commented
Feb 2, 2026
| pixel_ins_counter_d = pixel_ins_counter_q + 1; | ||
| state_d = READ; // so go to read | ||
|
|
||
| if(pixel_ins_counter_d >= PIXELS_NEEDED) begin // if we have enough pixels |
Owner
Author
There was a problem hiding this comment.
nit: Use previous counter == PIXELS_NEEDED-1 && pixel_valid_if_i.pixel
DonnyC123
commented
Feb 2, 2026
| CALCULATE : begin | ||
| // can only run this image len-1 time before we need to wait kernal_length cycles | ||
| // 2 x 2 = indexes: 0, 1, oldest, 2nd oldest | ||
| middle_value_r = get_middle_values(input_buffer_q[input_buffer_q.high()].red, |
Owner
Author
There was a problem hiding this comment.
This will become a latch. Just move outside your case statement
DonnyC123
commented
Feb 2, 2026
| end | ||
| end | ||
|
|
||
| CALCULATE : begin |
Owner
Author
There was a problem hiding this comment.
Can't handle recieving and processing Data at the same time.
DonnyC123
commented
Feb 2, 2026
|
|
||
|
|
||
| // Outputs | ||
| pixel_valid_if_o.pixel.red = get_adverage(middle_value_r); |
DonnyC123
commented
Feb 2, 2026
| // Takes: two logic values of PIXEL_W {a,b} | ||
| // Function: swaps if a > b | ||
| // Returns: the potentially swapped values {a,b} || {b,a} | ||
| function automatic logic [2*PIXEL_W-1:0] swap( |
DonnyC123
commented
Feb 2, 2026
| logic [2*PIXEL_W-1:0] swapped_vals; | ||
|
|
||
| // start | ||
| a = value1; b = value2; c = value3; d = value4; |
DonnyC123
commented
Feb 2, 2026
| // start | ||
| a = value1; b = value2; c = value3; d = value4; | ||
| // (a,b) | ||
| swapped_vals = swap(a,b); |
Owner
Author
There was a problem hiding this comment.
Should do 4 swaps:
low_1 high_1 = Swap(a, b)
low_2 high_2 = Swap(c, d)
mid1, ignore = Swap(high_1, high_2)
ignore, mid2 = Swap(low_1, low_2)
DonnyC123
commented
Feb 2, 2026
| // Takes: two pixel values rgb values appended together | ||
| // Function: does the adverage | ||
| // Returns: the adverage | ||
| function automatic logic [PIXEL_W-1:0] get_adverage (logic [PIXEL_W*2-1:0] values); |
Owner
Author
There was a problem hiding this comment.
Dont do weird packing stuff
DonnyC123
commented
Feb 2, 2026
| // Takes: 4 logic values of PIXEL_W (r || g || b) | ||
| // Function: Sorts those values | ||
| // Returns: the middle two of those sorted values appended together | ||
| function automatic logic [2*PIXEL_W-1:0] get_middle_values (logic [PIXEL_W-1:0] value1, logic [PIXEL_W-1:0] value2, |
Owner
Author
There was a problem hiding this comment.
Use an unpacked type [PIXEL_W-1:0] get_middle_values [2]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.