- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I searched for example and help with this subject in the forums but failed to find what I was looking for. If anyone can add on to my example code or point me in the right direction it would be much help.
I am using the Altera DE2 with the Cyclone II. I have connected, via the expansion header, the AD7843 LCD Touch Screen that typically comes with the DE2-70. I am trying to write a VHDL State Machine to set the control register, which means I have to constantly tell it to give me the X coordinates and then the Y coordinates from the A/D of the touch screen. I am building it based off of their datasheet diagrams and explanations and it would take too long to make someone read and understand so if anyone has already done this and can help fix my state machine I would be grateful. The code is below. PROCESS(DCLK, resetn, BUSY, CS)
-- VARIABLE count2 : INTEGER RANGE 0 TO 7; -- to wait a bit
VARIABLE count1 : INTEGER RANGE 0 to 1; -- Which Register
BEGIN
IF(resetn = '0') THEN -- Async reset, go to state 0
state <= s1;
ELSIF((DCLK'EVENT AND DCLK = '0') AND (BUSY = '0') AND (CS = '0')) THEN
CASE state IS
-- Enable Chip Select will be done automatically
-- when the Display register control is done. So
-- we just wait for BUSY signal to let us go.
WHEN s1 => DIN <= command(count1)(7); state <= s2;
WHEN s2 => DIN <= command(count1)(6); state <= s3;
WHEN s3 => DIN <= command(count1)(5); state <= s4;
WHEN s4 => DIN <= command(count1)(4); state <= s5;
WHEN s5 => DIN <= command(count1)(3); state <= s6;
WHEN s6 => DIN <= command(count1)(2); state <= s7;
WHEN s7 => DIN <= command(count1)(1); state <= s8;
WHEN s8 => DIN <= command(count1)(0); state <= s9;
-- read the DOUT line contents to temp variable
WHEN s9 => temp(11) <= DOUT; DIN <= '0'; state <= s10;
WHEN s10 => temp(10) <= DOUT; state <= s11;
WHEN s11 => temp(9) <= DOUT; state <= s12;
WHEN s12 => temp(8) <= DOUT; state <= s13;
WHEN s13 => temp(7) <= DOUT; state <= s14;
WHEN s14 => temp(6) <= DOUT; state <= s15;
WHEN s15 => temp(5) <= DOUT; state <= s16;
WHEN s16 => temp(4) <= DOUT; state <= s17;
WHEN s17 => temp(3) <= DOUT; state <= s18;
WHEN s18 => temp(2) <= DOUT; state <= s19;
WHEN s19 => temp(1) <= DOUT; state <= s20;
WHEN s20 => temp(0) <= DOUT; state <= s21;
-- Set our temp reg to whatevery coordinate from the analog
-- touch screen we want to read in. When count2 is 0, it is
-- x, else when count2 is 1, it is y.
WHEN s21 => IF(count1 = 0) THEN x <= temp; state <= s22;
ELSE y <= temp; state <= s22; END IF;
-- Check if the number of registers was set up, if we are
-- done, stay at last state to finish SPI, if not, go back
-- to the s1 and set up next register.
WHEN s22 => DIN <= '0'; IF(count1 >= 1) THEN count1 := 0; state <= s1;
ELSE count1 := count1 + 1; state <= s1; END IF;
END CASE;
END IF;
END PROCESS;
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page