// ********************************************************************
// The SendXY module toggles between sending the motor coordinates
// and the touch coordinates to the FGPA which has the camera interface
// on it.  It sends data 2-bits at a time, but when it sends the touch
// coordinates it inserts a 1 in its MSB which is our protocol that
// allows the camera interface to tell if the coordinate is touch or
// motor.

module SendXY (DataIn, CLK, RST, DataOut, MuxSel, Strobe) ;

input [31:0] DataIn ;
input CLK ;
input RST ;
output [1:0] DataOut ;
output MuxSel ;
output Strobe ;

reg [1:0] DataOut;
reg MuxSel;
reg [5:0] counter;
reg state;
reg Strobe;

reg [31:0] Data; // a temp hack

parameter SEL_MOTOR = 0,
          SEL_TOUCH = 1,
          SEND_TOUCH = 0,  // send touch coordinates
          SEND_MOTOR = 1;  // send motor coordinates

always @(posedge CLK) begin
    if (RST) begin
        state = SEND_MOTOR;
        Strobe = 0;
        counter = 0;
        MuxSel = SEL_MOTOR;  // select the motor
    end

    else begin
 
    Strobe = 0;
 
        case(state)
        SEND_MOTOR: begin
 
 
 
            if (counter > 15) begin  // send 2-bits for 16 times
                state = SEND_TOUCH;  // send touch coordinate after motor
                MuxSel = SEL_TOUCH;
                Strobe = 0;  // send Strobe back to low
                counter = 0;
            end

            else begin
                // send strobe high on 1st 2-bit nibble
                // and leave high since we send new nibble every cycle
                Strobe = 1;

                case (counter)  // send low X to high X, then low Y to high Y
                    6'b000000:  begin Data = DataIn;    DataOut = DataIn[17:16]; end
                    6'b000001:  DataOut = DataIn[19:18];
                    6'b000010:  DataOut = DataIn[21:20];
                    6'b000011:  DataOut = DataIn[23:22];
                    6'b000100:  DataOut = DataIn[25:24];
                    6'b000101:  DataOut = DataIn[27:26];
                    6'b000110:  DataOut = DataIn[29:28];
                    6'b000111:  DataOut = DataIn[31:30];
                    6'b001000:  DataOut = DataIn[1:0];
                    6'b001001:  DataOut = DataIn[3:2];
                    6'b001010:  DataOut = DataIn[5:4];
                    6'b001011:  DataOut = DataIn[7:6];
                    6'b001100:  DataOut = DataIn[9:8];
                    6'b001101:  DataOut = DataIn[11:10];
                    6'b001110:  DataOut = DataIn[13:12];
                    6'b001111:  DataOut = DataIn[15:14];
                endcase
                counter = (counter + 1);
            end // end if counter <= 15
        end  // end SEND_MOTOR case

        SEND_TOUCH: begin
            MuxSel = SEL_TOUCH;
 
            if (counter > 15) begin  // send 2-bits for 16 times
                state = SEND_MOTOR;  // after send Touch send Motor coordinates
                MuxSel = SEL_MOTOR;
                Strobe = 0;  // send Strobe back to low
                counter = 0;
            end
            else begin
                // send strobe high on 1st 2-bit nibble
                // and leave high since we send new nibble every cycle
                Strobe = 1;

                case (counter)  // send low X to high X, then low Y to high Y
                    6'b000000:  begin Data = DataIn;    DataOut = Data[17:16]; end
                    6'b000001:  DataOut = DataIn[19:18];
                    6'b000010:  DataOut = DataIn[21:20];
                    6'b000011:  DataOut = DataIn[23:22];
                    6'b000100:  DataOut = DataIn[25:24];
                    6'b000101:  DataOut = DataIn[27:26];
                    6'b000110:  DataOut = DataIn[29:28];
                    6'b000111:  DataOut = {1'b1, DataIn[30]}; // MSB of Touch coordinate is set to 1
                    6'b001000:  DataOut = DataIn[1:0];
                    6'b001001:  DataOut = DataIn[3:2];
                    6'b001010:  DataOut = DataIn[5:4];
                    6'b001011:  DataOut = DataIn[7:6];
                    6'b001100:  DataOut = DataIn[9:8];
                    6'b001101:  DataOut = DataIn[11:10];
                    6'b001110:  DataOut = DataIn[13:12];
                    6'b001111:  DataOut = {1'b1, DataIn[14]};
                endcase
                counter = (counter + 1);
            end // end if counter <= 15
        end  // end SEND_TOUCH case

        endcase // end state case

    end // end else not reset

end // end always at posedge CLK

endmodule
 
 
 

Back to Report