Skip to main content

RTC on FPGA with manual set synthesizeble VHDL code.

Hey there, cheers to VHDL. I successfully added manual set feature in my previous RTC project. I am not going to copy whole code here. I am just adding the links of .vhd files. I also added the pre-compiled .sof file only for DE1 boards. There is a very small bug that while clicking the set button to enable min and hr set, it increments the hr or min value unintentionally. Else everything is working great.

(Input freq 24MHz., top-level entity DigiClock)

On DE1 board: Push button functions.
  • Key0: Reset
  • Key1: Hour set (Key3 kept pressed)
  • Key2: Minute set (Key3 kept pressed)
  • Key3: Set enable.
Download links:
Video : 
    Do test the codes. If you have any querries do comment or mail me at

    Enjoy Programming..!!


    1. Hey,could you have any idea for date,month and year expression. I'm working with this topic

    2. @Binh: Its not that hard, just creat new components for date, month, year. Give the o/p of hour clock to date so after 24 hrs its value will be incremented. The o/p of date to month, and of mont to year.

      Create new process, which will tristate the o/p of clock on 7-seg and then display date, month and year one by one with small delay after pressing any push-button. And its done. If you want then I will add this feature to RTC code I posted. But try it by yourself first, that will only make you master.

    3. Thanks for answer but not easy as you said. Because after 4 years, we meet a Feb with 29 days. I will try. But let me ask you 2 questions:
      1,For 7 segment expression module: output is std_logic_vector(6 downto 0).But for input, my teacher used to BCD(4 bit). Whether we can use input as directly an integer 0->9? Does it run in reality?
      2, I want to add an ADC module in my work. An easy way to do is use an external ADC(8 bit) and then fpga will receive ADC output and express result. I wonder if we can "code" internal ADC in fpga? Something like input is levels of voltage from sensor, then fpga can understand the difference between these levels( 10mV for each) to push out 8 bits out?

    4. @Binh: 1. Yes, its possible and you can use Integer data type. But then you cant use that vhdl code as main entity. You had to decleare it as component in another entity and then send the integer data as component from your Main entity. Generally if unspecified then VHDL compiler will compile the Integer variable as 32-bit. But if you give it a range say 0 to 9 (for BCD) then it will only generate 4-bit register. You can check it from my modified 7-seg project file and also in this RTC code:

      2. Unfortunately there is no onchip ADC available on FPGA which we use. So you had to use the ADC IC.

      And the feb problem : Leap year can only get divided by 4 and others dont so design a code with this condition.

    5. Why in your code, "process(x,rst)" you used falling_edge(x) instead of raising_edge(x)? Other sounds ok, well done!

    6. @Binh: Very nice observation buddy. You just got corrected the error in code. Thats really a great help for me.

      When I was designing the code then I tried directly interfacing the Push Button to the process. As you know on DE1/DE2 board when button is not pressed then it has value '1' and when pressed '0'. For that I have made it falling_edge.

      But as it didn't worked, so I designed a clock for the incrementation and assigned the 'mi' o/p to 'x'.

      All these divided clocks works as '1' for half time and '0' for another. It means we should make it rising_edge else the first minute of clock after burning code will be only of 30 seconds. And rest all will be 60 seconds.

      Making it rising_edge will correct that error.
      I will upload the corrected code.
      Thanks again..!!

      And yes I have added Poll about projects quality, do vote. And keep posting your querries that will really help me, you and all our friends.

    7. @Binh: I think if we make correction of falling_edge to rising_edge, it directly increments min to 1 at start due to the rising_edge. Seems I had to modify the code to correct these errors. You also try.

    8. I think no problems for 1 minutes lead or lag (because of difference between seconds). Can you do buttons for date, month, year. I can't use buttons for them. Now I'm facing with coding for their expression. But it's still hard. For min, hr we can write sec_clk,min_clk for next module. I wrote hr_clk.But I think we can't write date_clk,month_clk. I intend to write like this:

      if year mode 4 =0
      if month=1,3,5...
      if day\=31 then...
      or we can use Mealy state machine. Can you help me because I am a new beginner in VHDL.

    9. Could You post the .pof file for this??!!!

    10. Thanks for your reference. I finished my projects well by myself!

    11. @Jace: Uploaded pof file for project.. Enjoy..

      @Binh: Thats great buddy...!! Keep it up.. you can share your work on blog if you want to.. I will post the updated files..

    12. i wanna ask,is it this program compatible with de2 board?...because my project using de2 board

    13. I keep getting an error when compiling the DigiClock file. It says Error (12002): Port "rsts" does not exist in macrofunction "c1"

    14. I wondered if you were aware that several of the dropdown menus in your blog don't have hyperlinks associated with the "a href" in your html webpage code. In other words, several of the headers like "projects, tutorials, need help..." don't go anywhere.


    Post a Comment

    Popular posts from this blog

    VHDL code for Clock Divider

    This is a clock divider code, just set the max-count value as per your requirenment.

    For ex. If I want 1Hz freq. set the max count to i/p freq value viz.
    1sec = 1Hz
    Then, to get time period of 1sec i.e. 1 Hz frequency set max-count to 240000 as shown below:

    1sec  =  24000000  -- for i/p frequency of 24 MHz.

    To get your desired frequency just calculate the maxcount with the formula given below:

    max_count = 24000000 * (1/your required frequency)


    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48libraryIEEE; useIEEE.STD_LOGIC_1164.ALL; useIEEE.numeric_std.all; entityclk_divisPort ( Clk :instd_logic; rst :instd_logic; op :outstd_logic ); endclk_div; architecturebehavioralofclk_divisconstant max_count :natural:=24000000; -- I used 24MHz clockbeginprocess(Clk,rst) variable count :naturalrange0to max_count; beginif rst ='0'…

    0 to 9999 bcd counter on seven segment(VHDL code) Synthesizeble

    --Note: while building Project do include sec_clk and seg7 files which i posted

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    use ieee.std_logic_unsigned.all;

    entity c09 is
    port( rst,clk: in std_logic;
          op0,op1,op2,op3: out std_logic_vector(6 downto 0));
    end c09;

    architecture count of c09 is

    component sec_clk
    Port (
               clk             : in  std_logic;
               rst : in std_logic;
               op  : out std_logic
        end component;

    component seg7
    port(m: in integer range 0 to 15;
         num: out std_logic_vector(6 downto 0));
    end component;

    signal flag: std_logic;
    signal a: integer range 0 to 10;
    signal b: integer range 0 to 10;
    signal c: integer range 0 to 10;
    signal d: integer range 0 to 10;

    c1: sec_clk port map(clk,rst,flag);

    variable m0: integer range 0 to 10:=0;
    variable m1: integer range 0 to 10:=0;
    variable m2: integer range 0 to 10:=0;
    variable m3: integer range 0 to 10:=0;


    if rst='0' then

    16x2 LCD Controller in VHDL

    Hello Everybody. The LCD 16x2 code is ready. Just one bug which is still not recognized. You need to program code 2 times on board to see it work. I dont know why its behaving like that.

    The text data is stored in a HEX file and is loaded onto the ROM of 32x8 byte size. It can be reconfigured easily.

    I will be uploading code in short of time with some new features.

    And after that be ready for a BMP decoder. Get ready with your pic to be seen on Monitor via FPGA.


    I didnt made  changes to code, if you program fpga 2 times without turning it off the code works(It worked on my DE1 board)
    I have uploaded project compiled for DE1 board, mail me your quiries, and if anyone finds bug in code.

    Project zip Download: