Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `timescale 1ns / 1ps
- // add in the no data display
- // Infrared Frequency detection and display
- // Version 4: removed HZLED funcionality
- // -changed freq_confirm to 2 bit var (from 1 bit), keeps track of which mailbox as well as confirms
- // -changed else block to conditional upon RM state. Makes sure freq_confirm keeps driving until mail is delivered
- // -ADDED ANOTHER IRsignal input!!
- // also, saved over V3... might need to go back to group folder and redownload
- // MAJOR CHOICE: keep L and R identification here
- // OR: revert back to only one sided inputs and let state machine decide which side!!!!!!
- module IR_frequency(
- input clk,
- //input [1:0] whisker, // MAYBE NEED THIS FOR DETERMINING WHICH SIGNAL TO TAKE IN
- input [1:0] IRsignal, // MSB = left side, LSB = right side!!!!!!
- input [1:0] state,
- //output reg LED10, LED100, LED1k, // to differentiate which frequency easily
- //output reg [2:0] HzLED, // 000 off, 001 10Hz, 010 100 Hz, 100 1kHz
- output reg [1:0] freq_confirm // 0 = off, 1 = 10 Hz, 2 = 100 Hz, 3 = 1Khz
- );
- // Going to confirm the mailbox by polling twice.
- // 10-1k Hz going to be chosen from 3 different ranges.
- // previous variables: no _L or _R, IRsignal was 1 bit, so was prevIR
- reg [26:0] fr_count; // counting up to 100 million
- reg [1:0] last;
- reg [10:0] data_store; // register to count data, data/8 = hertz/8
- reg [16:0] data; // LSB side of IRsignal input
- // changed mailbox/prevmailbox from 3 bit to 2 bit
- reg [1:0] mailbox;
- reg [1:0] prev_mailbox; // to compare current mailbox with for confirmation
- reg IR;
- reg prevIR;
- initial begin
- {fr_count, last, data_store, data, mailbox, prev_mailbox, IR, prevIR} = 0;
- end
- always@(posedge clk)
- begin
- if(state == 1) begin
- //freq_confirm = 0; // always zero unless confirm var.
- fr_count <= fr_count + 1;
- prevIR <= IR;
- IR <= IRsignal;
- if(IR && !prevIR)
- data <= data + 1;
- //data <= (IR && !prevIR)? data + 1 : data;
- data_store = data*5;
- //if(fr_count == 100000000) begin // 100 MHz
- if(fr_count == 20000000) begin // 100 MHz / 8 --->!!!1 maybe switch to 1 fifth!!
- //poll_flag = 1; // with it edited out, don't gotta worry about 7-seg
- fr_count <= 0;
- // NOTE: data_store, mailbox, and prev_mailbox all must have blocking assignments
- data_store = data * 5;
- //data_store_R = data_R * 5;
- data <= 0;
- // mailbox is current selection
- prev_mailbox = mailbox;
- mailbox = ((data_store >= 8) && (data_store <= 20)) ? 1 :
- ((data_store >= 80) && (data_store <= 200)) ? 2 :
- ((data_store >= 800) && (data_store <= 1200)) ? 3 : 0;
- if((prev_mailbox == mailbox) && mailbox != 0) begin
- freq_confirm = mailbox; // frequency has been confirmed
- // remobed HzLED variable, freq_confirm does all of it now
- //HzLED <= mailbox; // 3 bit mailbox feeds directly into HzLED's to show user
- end
- else
- freq_confirm = 0;
- end
- end // end IR state
- else if(state == 0) begin // in RM state
- //HzLED <= HzLED; // keeps on previously confirmed lights
- // HZLED TYPE VARIABLE REQUIRED TO KEEP DRIVING AN LED
- // SINCE FREQ CONFIRM MUST GO BACK TO 0 AFTER CONFIRMATION!!!
- freq_confirm <= 0; // confirm flag needs to be reset for next IR state
- end
- end
- endmodule
- // instead of rising/falling edge, every clock tick check IR signal
- // previous IR signal, current IR signal.
- // set both to zero
- // if(IRsignal && !prevIR) --> data <= data + 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement