OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_hd44780_4b.vhd] - Blame information for rev 183

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 175 jshamlet
-- VHDL Entity: o8_hd44780_4b
2
-- Description: Provides low-level access to a "standard" character LCD using
3
--               the ST/HD44780(U) control ASIC wired in reduced (4-bit) mode.
4
--              All low-level timing of the control signals are handled by this
5
--               module, allowing client firmware to use a simple register
6
--               interface to program the LCD panel.
7
--              Init routine initializes the display and displays a single
8
--               character to demonstrate correct function, then listens for
9
--               user data on its external interface.
10
 
11
library ieee;
12
use ieee.std_logic_1164.all;
13
use ieee.std_logic_unsigned.all;
14
use ieee.std_logic_arith.all;
15
 
16
library work;
17
use work.open8_pkg.all;
18
 
19
entity o8_hd44780_4b is
20
generic(
21
  Use_Contrast          : boolean;
22
  Default_Contrast      : std_logic_vector(7 downto 0);
23
  Use_Backlight         : boolean;
24
  Default_Brightness    : std_logic_vector(7 downto 0);
25
  Address               : ADDRESS_TYPE;
26
  Reset_Level           : std_logic;
27
  Sys_Freq              : real
28
);
29
port(
30
  Clock                 : in  std_logic;
31
  Reset                 : in  std_logic;
32
  --
33
  uSec_Tick             : in  std_logic;
34
  --
35
  Bus_Address           : in  ADDRESS_TYPE;
36
  Wr_Enable             : in  std_logic;
37
  Wr_Data               : in  DATA_TYPE;
38
  Rd_Enable             : in  std_logic;
39
  Rd_Data               : out DATA_TYPE;
40
  Interrupt             : out std_logic;
41
  --
42
  LCD_E                 : out std_logic;
43
  LCD_RW                : out std_logic;
44
  LCD_RS                : out std_logic;
45
  LCD_D                 : out std_logic_vector(7 downto 4);
46
  LCD_CN                : out std_logic;
47
  LCD_BL                : out std_logic
48
);
49
end entity;
50
 
51
architecture behave of o8_hd44780_4b is
52
 
53
  -- The ceil_log2 function returns the minimum register width required to
54
  --  hold the supplied integer.
55
  function ceil_log2 (x : in natural) return natural is
56
    variable retval          : natural;
57
  begin
58
    retval                   := 1;
59
    while ((2**retval) - 1) < x loop
60
      retval                 := retval + 1;
61
    end loop;
62
    return retval;
63
  end ceil_log2;
64
 
65
  constant User_Addr    : std_logic_vector(15 downto 2)
66
                          := Address(15 downto 2);
67
  alias  Comp_Addr      is Bus_Address(15 downto 2);
68
  signal Addr_Match     : std_logic;
69
 
70
  alias  Reg_Addr        is Bus_Address(1 downto 0);
71
  signal Reg_Addr_q     : std_logic_vector(1 downto 0);
72
 
73
  signal Wr_En          : std_logic;
74
  signal Wr_Data_q      : DATA_TYPE;
75
  signal Rd_En          : std_logic;
76
 
77
  signal Reg_Valid      : std_logic;
78
  signal Reg_Sel        : std_logic;
79
  signal Reg_Data       : std_logic_vector(7 downto 0);
80
 
81
  signal Tx_Ready       : std_logic;
82
 
83
--------------------------------------------------------------------------------
84
-- LCD Controller
85
--------------------------------------------------------------------------------
86
 
87
-- Register Map
88
-- Address  Function
89
-- Offset  Bitfield Description                        Read/Write
90
-- 0x0     AAAAAAAA LCD Register Write                 (Write-only)
91
-- 0x1     AAAAAAAA LCD Data Write                     (Write-only)
92
-- 0x2     AAAAAAAA LCD Contrast                       (Read-Write)
93
-- 0x3     AAAAAAAA LCD Backlight                      (Read-Write)
94
 
95
-- LCD Instruction Set
96
-- Instruction             RS  RW  D7  D6  D5  D4  D3  D2  D1  D0  Time
97
------------------------------------------------------------------------
98
-- Clear Display         | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1.52mS
99
-- Return Home           | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | x | 1.52mS
100
-- Entry Mode            | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | ID| S |   37uS
101
-- Display Pwr           | 0 | 0 | 0 | 0 | 0 | 0 | 1 | D | C | B |   37uS
102
-- Cursor/Display Shift  | 0 | 0 | 0 | 0 | 0 | 1 | SC| RL| x | x |   37uS
103
-- Function Set          | 0 | 0 | 0 | 0 | 1 | DL| N | F | x | x |   37uS
104
-- Set CGRAM Address     | 0 | 0 | 0 | 1 | A | A | A | A | A | A |   37uS
105
-- Set DDRAM Address     | 0 | 0 | 1 | A | A | A | A | A | A | A |   37uS
106
 
107
-- Notes:
108
-- ID = Increment/Decrement DDRAM Address (1 = increment, 0 = decrement)
109
-- S  = Shift Enable (1 = Shift display according to ID, 0 = Don't shift)
110
-- D  = Display On/Off (1 = on, 0 = off)
111
-- C  = Cursor On/Off  (1 = on, 0 = off)
112
-- B  = Cursor Blink   (1 = block cursor, 0 = underline cursor)
113
-- SC / RL = Shift Cursor/Display Right/Left (see data sheet - not needed for init)
114
-- F  = Font (0 = 5x8, 1 = 5x11) Ignored on 2-line displays (N = 1)
115
-- N  = Number of Lines (0 = 1 lines, 1 = 2 lines)
116
-- DL = Data Length (0 = 4-bit bus, 1 = 8-bit bus) This is fixed at 0 in this module
117
-- A  = Address (see data sheet for usage)
118
 
119
  constant LCD_CONFIG1  : std_logic_vector(7 downto 4) := x"3";  -- Init to 4-bit mode
120
  constant LCD_CONFIG2  : std_logic_vector(7 downto 0) := x"28"; -- Set 4-bit, 2-line mode
121
  constant LCD_CONFIG3  : std_logic_vector(7 downto 0) := x"0C"; -- Turn display on, no cursor
122
  constant LCD_CONFIG4  : std_logic_vector(7 downto 0) := x"01"; -- Clear display
123
  constant LCD_CONFIG5  : std_logic_vector(7 downto 0) := x"06"; -- Positive increment, no shift
124
  constant LCD_CONFIG6  : std_logic_vector(7 downto 0) := x"2A"; -- Print a "*"
125
  constant LCD_CONFIG7  : std_logic_vector(7 downto 0) := x"02"; -- Reset the cursor
126
 
127
  signal init_count     : std_logic_vector(2 downto 0);
128
 
129
  constant INIT_40MS    : integer := 40000;
130
  constant INIT_BITS    : integer := ceil_log2(INIT_40MS);
131
  constant INIT_DELAY   : std_logic_vector(INIT_BITS-1 downto 0) :=
132
                          conv_std_logic_vector(INIT_40MS,INIT_BITS);
133
 
134
-- For "long" instructions, such as clear display and return home, we need to wait for more
135
--  than 1.52mS. Experimentally, 2mS seems to work ideally, and for init this isn't an issue
136
  constant CLDSP_2MS    : integer := 2000;
137
  constant CLDSP_DELAY  : std_logic_vector(INIT_BITS-1 downto 0) :=
138
                          conv_std_logic_vector(CLDSP_2MS,INIT_BITS);
139
 
140
 -- For some reason, we are required to wait 80uS before checking the busy flag, despite
141
 --  most instructions completing in 37uS. No clue as to why, but it works
142
  constant BUSY_50US    : integer := 50;
143
  constant BUSY_DELAY   : std_logic_vector(INIT_BITS-1 downto 0) :=
144
                          conv_std_logic_vector(BUSY_50US-1, INIT_BITS);
145
 
146
  signal busy_timer     : std_logic_vector(INIT_BITS-1 downto 0);
147
 
148
  constant SNH_600NS    : integer := integer(Sys_Freq * 0.000000600);
149
  constant SNH_BITS     : integer := ceil_log2(SNH_600NS);
150
  constant SNH_DELAY    : std_logic_vector(SNH_BITS-1 downto 0) :=
151
                          conv_std_logic_vector(SNH_600NS-1, SNH_BITS);
152
 
153
  signal io_timer       : std_logic_vector(SNH_BITS - 1 downto 0);
154
 
155
  type IO_STATES is (INIT, PWR_WAIT, INIT_S1, INIT_H1,
156
                     INIT_WAIT, FN_JUMP, IDLE,
157
                                         WR_PREP, WR_SETUP_UB, WR_HOLD_UB, WR_SETUP_LB, WR_HOLD_LB,
158
                     BUSY_PREP, BUSY_WAIT,
159
                     ISSUE_INT );
160
 
161
  signal io_state       : IO_STATES;
162
 
163
  signal LCD_Data       : std_logic_vector(7 downto 0);
164
  signal LCD_Addr       : std_logic;
165
 
166
--------------------------------------------------------------------------------
167
-- Backlight signals
168
--------------------------------------------------------------------------------
169
 
170
  -- Do not adjust alone! DELTA constants must be
171
  --  changed as well.
172
  constant DAC_Width    : integer := 8;
173
 
174
  constant DELTA_1_I    : integer := 1;
175
  constant DELTA_2_I    : integer := 5;
176
  constant DELTA_3_I    : integer := 25;
177
  constant DELTA_4_I    : integer := 75;
178
  constant DELTA_5_I    : integer := 125;
179
  constant DELTA_6_I    : integer := 195;
180
 
181
  constant DELTA_1      : std_logic_vector(DAC_Width-1 downto 0) :=
182
                           conv_std_logic_vector(DELTA_1_I, DAC_Width);
183
  constant DELTA_2      : std_logic_vector(DAC_Width-1 downto 0) :=
184
                           conv_std_logic_vector(DELTA_2_I, DAC_Width);
185
  constant DELTA_3      : std_logic_vector(DAC_Width-1 downto 0) :=
186
                           conv_std_logic_vector(DELTA_3_I, DAC_Width);
187
  constant DELTA_4      : std_logic_vector(DAC_Width-1 downto 0) :=
188
                           conv_std_logic_vector(DELTA_4_I, DAC_Width);
189
  constant DELTA_5      : std_logic_vector(DAC_Width-1 downto 0) :=
190
                           conv_std_logic_vector(DELTA_5_I, DAC_Width);
191
  constant DELTA_6      : std_logic_vector(DAC_Width-1 downto 0) :=
192
                           conv_std_logic_vector(DELTA_6_I, DAC_Width);
193
 
194
  constant MAX_PERIOD   : integer := 2**DAC_Width;
195
  constant DIV_WIDTH    : integer := DAC_Width * 2;
196
 
197
  constant PADJ_1_I     : integer := DELTA_1_I * MAX_PERIOD;
198
  constant PADJ_2_I     : integer := DELTA_2_I * MAX_PERIOD;
199
  constant PADJ_3_I     : integer := DELTA_3_I * MAX_PERIOD;
200
  constant PADJ_4_I     : integer := DELTA_4_I * MAX_PERIOD;
201
  constant PADJ_5_I     : integer := DELTA_5_I * MAX_PERIOD;
202
  constant PADJ_6_I     : integer := DELTA_6_I * MAX_PERIOD;
203
 
204
  constant PADJ_1       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
205
                           conv_std_logic_vector(PADJ_1_I,DIV_WIDTH);
206
  constant PADJ_2       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
207
                           conv_std_logic_vector(PADJ_2_I,DIV_WIDTH);
208
  constant PADJ_3       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
209
                           conv_std_logic_vector(PADJ_3_I,DIV_WIDTH);
210
  constant PADJ_4       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
211
                           conv_std_logic_vector(PADJ_4_I,DIV_WIDTH);
212
  constant PADJ_5       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
213
                           conv_std_logic_vector(PADJ_5_I,DIV_WIDTH);
214
  constant PADJ_6       : std_logic_vector(DIV_WIDTH-1 downto 0) :=
215
                           conv_std_logic_vector(PADJ_6_I,DIV_WIDTH);
216
 
217
  constant CB           : integer := ceil_log2(DIV_WIDTH);
218
 
219
  signal LCD_Contrast   : std_logic_vector(7 downto 0);
220
 
221
  signal CN_DACin       : std_logic_vector(DAC_WIDTH-1 downto 0);
222
 
223
  signal CN_Divisor     : std_logic_vector(DIV_WIDTH-1 downto 0);
224
  signal CN_Dividend    : std_logic_vector(DIV_WIDTH-1 downto 0);
225
 
226
  signal CN_q           : std_logic_vector(DIV_WIDTH*2-1 downto 0);
227
  signal CN_diff        : std_logic_vector(DIV_WIDTH downto 0);
228
 
229
  signal CN_count       : std_logic_vector(CB-1 downto 0);
230
 
231
  signal CN_Next_Wdt    : std_logic_vector(DAC_Width-1 downto 0);
232
  signal CN_Next_Per    : std_logic_vector(DAC_Width-1 downto 0);
233
 
234
  signal CN_PWM_Wdt     : std_logic_vector(DAC_Width-1 downto 0);
235
  signal CN_PWM_Per     : std_logic_vector(DAC_Width-1 downto 0);
236
 
237
  signal CN_Wdt_Ctr     : std_logic_vector(DAC_Width-1 downto 0);
238
  signal CN_Per_Ctr     : std_logic_vector(DAC_Width-1 downto 0);
239
 
240
  signal LCD_Bright     : std_logic_vector(7 downto 0);
241
 
242
  signal BL_DACin       : std_logic_vector(DAC_WIDTH-1 downto 0);
243
 
244
  signal BL_Divisor     : std_logic_vector(DIV_WIDTH-1 downto 0);
245
  signal BL_Dividend    : std_logic_vector(DIV_WIDTH-1 downto 0);
246
 
247
  signal BL_q           : std_logic_vector(DIV_WIDTH*2-1 downto 0);
248
  signal BL_diff        : std_logic_vector(DIV_WIDTH downto 0);
249
 
250
  signal BL_count       : std_logic_vector(CB-1 downto 0);
251
 
252
  signal BL_Next_Wdt    : std_logic_vector(DAC_Width-1 downto 0);
253
  signal BL_Next_Per    : std_logic_vector(DAC_Width-1 downto 0);
254
 
255
  signal BL_PWM_Wdt     : std_logic_vector(DAC_Width-1 downto 0);
256
  signal BL_PWM_Per     : std_logic_vector(DAC_Width-1 downto 0);
257
 
258
  signal BL_Wdt_Ctr     : std_logic_vector(DAC_Width-1 downto 0);
259
  signal BL_Per_Ctr     : std_logic_vector(DAC_Width-1 downto 0);
260
begin
261
 
262
--------------------------------------------------------------------------------
263
-- Open8 Register interface
264
--------------------------------------------------------------------------------
265
 
266
  Addr_Match            <= '1' when Comp_Addr = User_Addr else '0';
267
 
268
  io_reg: process( Clock, Reset )
269
  begin
270
    if( Reset = Reset_Level )then
271
      Reg_Addr_q        <= (others => '0');
272
      Wr_Data_q         <= (others => '0');
273
      Wr_En             <= '0';
274
      Rd_En             <= '0';
275
      Rd_Data           <= (others => '0');
276
 
277
      Reg_Valid         <= '0';
278
      Reg_Sel           <= '0';
279
      Reg_Data          <= x"00";
280
 
281
      LCD_Contrast      <= Default_Contrast;
282
      LCD_Bright        <= Default_Brightness;
283
    elsif( rising_edge( Clock ) )then
284
      Reg_Addr_q        <= Reg_Addr;
285
 
286
      Wr_Data_q         <= Wr_Data;
287
      Wr_En             <= Addr_Match and Wr_Enable;
288
 
289
      Reg_Valid         <= '0';
290
 
291
      if( Wr_En = '1' )then
292
        case( Reg_Addr_q )is
293
          when "00" | "01" =>
294
            Reg_Valid   <= '1';
295
            Reg_Sel     <= Reg_Addr_q(0);
296
            Reg_Data    <= Wr_Data_q;
297
          when "10" =>
298
            LCD_Contrast<= Wr_Data_q;
299
          when "11" =>
300
            LCD_Bright  <= Wr_Data_q;
301
          when others => null;
302
        end case;
303
      end if;
304
 
305
      Rd_Data           <= (others => '0');
306
      Rd_En             <= Addr_Match and Rd_Enable;
307
      if( Rd_En = '1' )then
308
        case( Reg_Addr_q )is
309
          when "00" | "01" =>
310
            Rd_Data(7)  <= Tx_Ready;
311
          when "10" =>
312
            Rd_Data     <= LCD_Contrast;
313
          when "11" =>
314
            Rd_Data     <= LCD_Bright;
315
          when others => null;
316
        end case;
317
      end if;
318
    end if;
319
  end process;
320
 
321
--------------------------------------------------------------------------------
322
-- LCD and Register logic
323
--------------------------------------------------------------------------------
324
 
325
  LCD_RW                <= '0'; -- Permanently wire the RW line low
326
 
327
  LCD_IO: process( Clock, Reset )
328
  begin
329
    if( Reset = Reset_Level )then
330
      io_state          <= INIT;
331
      init_count        <= (others => '0');
332
      io_timer          <= (others => '0');
333
      busy_timer        <= (others => '0');
334
      LCD_Data          <= (others => '0');
335
      LCD_Addr          <= '0';
336
      LCD_E             <= '0';
337
      LCD_RS            <= '0';
338
      LCD_D             <= (others => '0');
339
      Tx_Ready          <= '0';
340
      Interrupt         <= '0';
341
    elsif( rising_edge(Clock) )then
342
      LCD_E             <= '0';
343
      LCD_RS            <= '0';
344
      LCD_D             <= (others => '0');
345
      Tx_Ready          <= '0';
346
      Interrupt         <= '0';
347
      io_timer          <= io_timer - 1;
348
      busy_timer        <= busy_timer - uSec_Tick;
349
      case( io_state )is
350
 
351
        when INIT =>
352
          busy_timer    <= INIT_DELAY;
353
          init_count    <= (others => '1');
354
          io_state      <= PWR_WAIT;
355
 
356
        -- We wait for at least 40mS before continuing initalization.
357
        when PWR_WAIT =>
358
          if( busy_timer = 0 )then
359
            io_timer    <= SNH_DELAY;
360
            io_state    <= INIT_S1;
361
          end if;
362
 
363
        -- We write out the first init byte as if we were using an 8-bit
364
        --  data bus, with a single cycle. This is an exception, and the
365
        --  rest of the commands are sent using 2-cycle transfers.
366
        when INIT_S1 =>
367
          LCD_D         <= LCD_CONFIG1;
368
          LCD_E         <= '1';
369
          if( io_timer = 0 )then
370
            io_timer    <= SNH_DELAY;
371
            io_state    <= INIT_H1;
372
          end if;
373
 
374
        when INIT_H1 =>
375
          LCD_D         <= LCD_CONFIG1;
376
          if( io_timer = 0 )then
377
            busy_timer  <= BUSY_DELAY;
378
            io_state    <= INIT_WAIT;
379
          end if;
380
 
381
        when INIT_WAIT =>
382
          if( busy_timer = 0 )then
383
            io_state    <= FN_JUMP;
384
          end if;
385
 
386
        when FN_JUMP =>
387
          io_state      <= WR_PREP;
388
          case( init_count )is
389
            when "000" =>
390
              io_state  <= IDLE;
391
            when "001" =>
392
              LCD_Addr  <= '0';
393
              LCD_Data  <= LCD_CONFIG7; -- Reset the Cursor
394
            when "010" =>
395
              LCD_Addr  <= '1';         -- Print a "*", and
396
              LCD_Data  <= LCD_CONFIG6; --  set RS to 1
397
            when "011" =>
398
              LCD_Data  <= LCD_CONFIG5; -- Entry mode
399
            when "100" =>
400
              LCD_Data  <= LCD_CONFIG4; -- Clear Display
401
            when "101" =>
402
              LCD_Data  <= LCD_CONFIG3; -- Display control
403
            when "110" | "111" =>
404
              LCD_Addr  <= '0';
405
              LCD_Data  <= LCD_CONFIG2; -- Function set
406
            when others => null;
407
          end case;
408
 
409
        when IDLE =>
410
          Tx_Ready      <= '1';
411
          if( Reg_Valid = '1' )then
412
            LCD_Addr    <= Reg_Sel;
413
            LCD_Data    <= Reg_Data;
414
            io_state    <= WR_PREP;
415
          end if;
416
 
417
        when WR_PREP =>
418
          io_timer      <= SNH_DELAY;
419
          io_state      <= WR_SETUP_UB;
420
 
421
        when WR_SETUP_UB =>
422
          LCD_RS        <= LCD_Addr;
423
          LCD_D         <= LCD_Data(7 downto 4);
424
          LCD_E         <= '1';
425
          if( io_timer = 0 )then
426
            io_timer    <= SNH_DELAY;
427
            io_state    <= WR_HOLD_UB;
428
          end if;
429
 
430
        when WR_HOLD_UB =>
431
          LCD_RS        <= LCD_Addr;
432
          LCD_D         <= LCD_Data(7 downto 4);
433
          if( io_timer = 0 )then
434
            LCD_E       <= '0';
435
            io_timer    <= SNH_DELAY;
436
            io_state    <= WR_SETUP_LB;
437
          end if;
438
 
439
        when WR_SETUP_LB =>
440
          LCD_RS        <= LCD_Addr;
441
          LCD_D         <= LCD_Data(3 downto 0);
442
          LCD_E         <= '1';
443
          if( io_timer = 0 )then
444
            io_timer    <= SNH_DELAY;
445
            io_state    <= WR_HOLD_LB;
446
          end if;
447
 
448
        when WR_HOLD_LB =>
449
          LCD_RS        <= LCD_Addr;
450
          LCD_D         <= LCD_Data(3 downto 0);
451
          if( io_timer = 0 )then
452
            io_state    <= BUSY_WAIT;
453
          end if;
454
 
455
        when BUSY_PREP =>
456
          busy_timer    <= BUSY_DELAY;
457
          if( LCD_Addr = '0' and LCD_Data < 4 )then
458
            busy_timer  <= CLDSP_DELAY;
459
          end if;
460
          io_state      <= BUSY_WAIT;
461
 
462
        when BUSY_WAIT =>
463
          if( busy_timer = 0 )then
464
            io_state    <= ISSUE_INT;
465
            if( init_count > 0 )then
466
              init_count<= init_count - 1;
467
              io_state  <= FN_JUMP;
468
            end if;
469
          end if;
470
 
471
        when ISSUE_INT =>
472
          Interrupt     <= '1';
473
          io_state      <= IDLE;
474
 
475
        when others => null;
476
 
477
      end case;
478
 
479
    end if;
480
  end process;
481
 
482
--------------------------------------------------------------------------------
483
-- Contrast control logic (optional)
484
--------------------------------------------------------------------------------
485
 
486
Contrast_Disabled: if( not Use_Contrast )generate
487
  LCD_CN                <= '0';
488
end generate;
489
 
490
Contrast_Enabled: if( Use_Contrast )generate
491
 
492
  CN_diff               <= ('0' & CN_q(DIV_WIDTH*2-2 downto DIV_WIDTH-1)) -
493
                           ('0' & CN_Divisor);
494
 
495
  CN_Dividend<= PADJ_2 when CN_DACin >= DELTA_2_I and CN_DACin < DELTA_3_I else
496
                PADJ_3 when CN_DACin >= DELTA_3_I and CN_DACin < DELTA_4_I else
497
                PADJ_4 when CN_DACin >= DELTA_4_I and CN_DACin < DELTA_5_I else
498
                PADJ_5 when CN_DACin >= DELTA_5_I and CN_DACin < DELTA_6_I else
499
                PADJ_6 when CN_DACin >= DELTA_6_I else
500
                PADJ_1;
501
 
502
  CN_Next_Wdt<= DELTA_1 when CN_DACin >= DELTA_1_I and CN_DACin < DELTA_2_I else
503
                DELTA_2 when CN_DACin >= DELTA_2_I and CN_DACin < DELTA_3_I else
504
                DELTA_3 when CN_DACin >= DELTA_3_I and CN_DACin < DELTA_4_I else
505
                DELTA_4 when CN_DACin >= DELTA_4_I and CN_DACin < DELTA_5_I else
506
                DELTA_5 when CN_DACin >= DELTA_5_I and CN_DACin < DELTA_6_I else
507
                DELTA_6 when CN_DACin >= DELTA_6_I else
508
                (others => '0');
509
 
510
  CN_Next_Per           <= BL_q(7 downto 0) - 1;
511
 
512
  CN_vDSM_proc: process( Clock, Reset )
513
  begin
514
    if( Reset = Reset_Level )then
515
      CN_q              <= (others => '0');
516
      CN_count          <= (others => '1');
517
      CN_Divisor        <= (others => '0');
518
      CN_DACin          <= (others => '0');
519
      CN_PWM_Wdt        <= (others => '0');
520
      CN_PWM_Per        <= (others => '0');
521
      CN_Per_Ctr        <= (others => '0');
522
      CN_Wdt_Ctr        <= (others => '0');
523
      LCD_CN            <= '0';
524
    elsif( rising_edge(Clock) )then
525
      CN_q              <= CN_diff(DIV_WIDTH-1 downto 0) &
526
                           CN_q(DIV_WIDTH-2 downto 0) & '1';
527
      if( CN_diff(DIV_WIDTH) = '1' )then
528
        CN_q            <= CN_q(DIV_WIDTH*2-2 downto 0) & '0';
529
      end if;
530
 
531
      CN_count          <= CN_count + 1;
532
      if( CN_count = DIV_WIDTH )then
533
        CN_PWM_Wdt      <= CN_Next_Wdt;
534
        CN_PWM_Per      <= CN_Next_Per;
535
        CN_DACin        <= LCD_Contrast;
536
        CN_Divisor      <= (others => '0');
537
        CN_Divisor(DAC_Width-1 downto 0) <= CN_DACin;
538
        CN_q            <= conv_std_logic_vector(0,DIV_WIDTH) & CN_Dividend;
539
        CN_count        <= (others => '0');
540
      end if;
541
 
542
      CN_Per_Ctr        <= CN_Per_Ctr - 1;
543
      CN_Wdt_Ctr        <= CN_Wdt_Ctr - 1;
544
 
545
      LCD_CN            <= '1';
546
      if( CN_Wdt_Ctr = 0 )then
547
        LCD_CN          <= '0';
548
        CN_Wdt_Ctr      <= (others => '0');
549
      end if;
550
 
551
      if( CN_Per_Ctr = 0 )then
552
        CN_Per_Ctr      <= CN_PWM_Per;
553
        CN_Wdt_Ctr      <= CN_PWM_Wdt;
554
      end if;
555
 
556
    end if;
557
  end process;
558
end generate;
559
 
560
--------------------------------------------------------------------------------
561
-- Backlight control logic (optional)
562
--------------------------------------------------------------------------------
563
 
564
Backlight_Disabled: if( not Use_Backlight )generate
565
  LCD_BL                <= '0';
566
end generate;
567
 
568
Backlight_Enabled: if( Use_Backlight )generate
569
 
570
  BL_diff               <= ('0' & BL_q(DIV_WIDTH*2-2 downto DIV_WIDTH-1)) -
571
                           ('0' & BL_Divisor);
572
 
573
  BL_Dividend<= PADJ_2 when BL_DACin >= DELTA_2_I and BL_DACin < DELTA_3_I else
574
                PADJ_3 when BL_DACin >= DELTA_3_I and BL_DACin < DELTA_4_I else
575
                PADJ_4 when BL_DACin >= DELTA_4_I and BL_DACin < DELTA_5_I else
576
                PADJ_5 when BL_DACin >= DELTA_5_I and BL_DACin < DELTA_6_I else
577
                PADJ_6 when BL_DACin >= DELTA_6_I else
578
                PADJ_1;
579
 
580
  BL_Next_Wdt<= DELTA_1 when BL_DACin >= DELTA_1_I and BL_DACin < DELTA_2_I else
581
                DELTA_2 when BL_DACin >= DELTA_2_I and BL_DACin < DELTA_3_I else
582
                DELTA_3 when BL_DACin >= DELTA_3_I and BL_DACin < DELTA_4_I else
583
                DELTA_4 when BL_DACin >= DELTA_4_I and BL_DACin < DELTA_5_I else
584
                DELTA_5 when BL_DACin >= DELTA_5_I and BL_DACin < DELTA_6_I else
585
                DELTA_6 when BL_DACin >= DELTA_6_I else
586
                (others => '0');
587
 
588
  BL_Next_Per           <= BL_q(7 downto 0) - 1;
589
 
590
  BL_vDSM_proc: process( Clock, Reset )
591
  begin
592
    if( Reset = Reset_Level )then
593
      BL_q              <= (others => '0');
594
      BL_count          <= (others => '1');
595
      BL_Divisor        <= (others => '0');
596
      BL_DACin        <= (others => '0');
597
      BL_PWM_Wdt        <= (others => '0');
598
      BL_PWM_Per        <= (others => '0');
599
      BL_Per_Ctr        <= (others => '0');
600
      BL_Wdt_Ctr        <= (others => '0');
601
      LCD_BL            <= '0';
602
    elsif( rising_edge(Clock) )then
603
      BL_q              <= BL_diff(DIV_WIDTH-1 downto 0) &
604
                           BL_q(DIV_WIDTH-2 downto 0) & '1';
605
      if( BL_diff(DIV_WIDTH) = '1' )then
606
        BL_q            <= BL_q(DIV_WIDTH*2-2 downto 0) & '0';
607
      end if;
608
 
609
      BL_count          <= BL_count + 1;
610
      if( BL_count = DIV_WIDTH )then
611
        BL_PWM_Wdt      <= BL_Next_Wdt;
612
        BL_PWM_Per      <= BL_Next_Per;
613
        BL_DACin      <= LCD_Bright;
614
        BL_Divisor      <= (others => '0');
615
        BL_Divisor(DAC_Width-1 downto 0) <= BL_DACin;
616
        BL_q            <= conv_std_logic_vector(0,DIV_WIDTH) & BL_Dividend;
617
        BL_count        <= (others => '0');
618
      end if;
619
 
620
      BL_Per_Ctr        <= BL_Per_Ctr - 1;
621
      BL_Wdt_Ctr        <= BL_Wdt_Ctr - 1;
622
 
623
      LCD_BL            <= '1';
624
      if( BL_Wdt_Ctr = 0 )then
625
        LCD_BL          <= '0';
626
        BL_Wdt_Ctr      <= (others => '0');
627
      end if;
628
 
629
      if( BL_Per_Ctr = 0 )then
630
        BL_Per_Ctr      <= BL_PWM_Per;
631
        BL_Wdt_Ctr      <= BL_PWM_Wdt;
632
      end if;
633
 
634
    end if;
635
  end process;
636
 
637
end generate;
638
 
639
end architecture;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.