{"id":1599,"date":"2024-06-26T14:27:27","date_gmt":"2024-06-26T14:27:27","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=1599"},"modified":"2024-08-11T16:14:35","modified_gmt":"2024-08-11T16:14:35","slug":"digital-clock-industrial-load-controller","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=1599","title":{"rendered":"Digital Clock &amp; Industrial Load Controller"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color wp-elements-c3b304c0c93516f2c0d789a542441bb9 wp-block-paragraph\" style=\"color:#5c5c5c\">Let\u2019s make a Digital Clock to display seconds, minute &amp; hour to seven segment displays. Here 6 seven segment display are used. We make it in 3 steps. First initial timer1 interrupt at 1s delay. In this project we use ATmega32 with external crystal with 8MHz at <\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-f605b9cd2f2784d24acaa62b3e4d7fb4 wp-block-paragraph\" style=\"color:#202020\">           <strong>HFUSE=0x89          LFUSE=0xEF<\/strong><\/p>\n\n\n\n<p class=\"has-text-align-left has-text-color has-link-color wp-elements-df82f61e2bbbcffc8074d5205c54749d wp-block-paragraph\" style=\"color:#292929\"><img decoding=\"async\" width=\"41\" height=\"40\" class=\"wp-image-944\" style=\"width: 41px;\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/float.jpg\" alt=\"\">Timer1 interrupt with 1s counting<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nTCCR1B|=(1&lt;&lt;WGM12)|(1&lt;&lt;CS12);       \/\/MODE4 CTC with prescaler 256\nTCNT1=0;\t\t\t\t\t\t\t \/\/clear Timer\nTIMSK|=(1&lt;&lt;OCIE1A);\t\t\t\t\t \/\/Timer\/Counter1 Output Compare Match Interrupt Enable\nsei();\t\t\t\t\t\t\t\t \/\/Globel Interrupt Enable\nOCR1A=31249;\t\t\t\t\t\t \/\/F_CPU=8MHz,P=256,Delay=1s\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-2b2443df3fdfc4236334c3a003335fd4 wp-block-paragraph\" style=\"color:#5c5c5c\">In interrupt service routine we call the seven segment part to display. Now the second display in last 2 seven segments, minute in 3<sup>rd<\/sup> and 4<sup>th<\/sup> and hour in 5<sup>th<\/sup> and 6<sup>th<\/sup>. Say the digit is stored in an integer array. Then the control logic is-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n   digits &#x5B;0]=second%10; \n   digits &#x5B;1]=second\/10;\n   digits &#x5B;2]=minute%10;\n   digits &#x5B;3]=minute\/10;\n   digits &#x5B;4]=hour%10;\n   digits &#x5B;5]=hour%10;\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-85955eb33fbba13d1614d898abbd0d2f wp-block-paragraph\" style=\"color:#5c5c5c\">We already learn about global variable. Now we used it. Declear int digits[6] in header file. In interrupt service routine-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nuint8_t second,minute,hour;\nISR(TIMER1_COMPA_vect)\n{\n\tsecond++;\n\tif(second==60){\n\t\tminute++;\n\t\tdigits&#x5B;2]=minute%10;\n\t    digits&#x5B;3]=minute\/10;\n\t\tsecond=0;\n\t}\n\tdigits&#x5B;0]=second%10;\n\tdigits&#x5B;1]=second\/10;\n\t\tif(minute==60){\n\t\t\thour++;\n\t\t\tdigits&#x5B;4]=hour%10;\n\t        digits&#x5B;5]=hour\/10;\n\t\t\tminute=0;\n\t\t\tif(hour==24) hour=0;\n\t\t}\n}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-1198a40c40cbfd7978d87b623f5abff2 wp-block-paragraph\" style=\"color:#5c5c5c\">Now for persistence of vision we previously used _delay_ms() function but in real time calculation we can\u2019t used delay to hold CPU. So we use a timer in this case use Timer0 for 1ms duration. We don\u2019t use interrupt service routine, rather that we use flag register.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"627\" height=\"45\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/1ms_delay.jpg\" alt=\"\" class=\"wp-image-1615\" style=\"width:334px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/1ms_delay.jpg 627w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/1ms_delay-300x22.jpg 300w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nvoid delay_ms_1(void)\n{\n\twhile(!(TIFR&amp;(1&lt;&lt;OCF0)))\n\t{\n\t \/\/wait for 1ms until the flag is set\n\t}\n\tTIFR|=(1&lt;&lt;OCF0); \/\/clear the flag\n}\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"37\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/download-program1-1024x37.jpg\" alt=\"\" class=\"wp-image-1617\" style=\"width:554px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/download-program1-1024x37.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/download-program1-300x11.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/download-program1-768x28.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/download-program1.jpg 1048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n#include&lt;avr\/io.h&gt;\n#include&lt;stdio.h&gt;\n#include&lt;util\/delay.h&gt;\n#include&lt;avr\/interrupt.h&gt;\n#include&quot;count.h&quot;\nint main(void)\n{\nDDRB=0xff;\t\t\t\t\t\t\t\/\/7 segment port\nPORTB=0b11111100;\t\t\t\t\t\/\/default value 0 to all the 7 segment;\nDDRC=0x3f;\t\t\t\t\t\t\t\/\/7 segment control port\n\/*********************************************************************************************\n***********  Timer1 for 1s delay  F_CPU=8MHz, Prescaler 256 Top value OCR    ****************\/\n\/********************************************************************************************\/                         \nTCCR1B|=(1&lt;&lt;WGM12)|(1&lt;&lt;CS12);       \/\/MODE4 CTC with prescaler 256\nTCNT1=0;\t\t\t\t\t\t\t \/\/clear Timer\nTIMSK|=(1&lt;&lt;OCIE1A);\t\t\t\t\t \/\/Timer\/Counter1 Output Compare Match Interrupt Enable\nsei();\t\t\t\t\t\t\t\t \/\/Globel Interrupt Enable\nOCR1A=31249;\t\t\t\t\t\t \/\/F_CPU=8MHz,P=256,Delay=1s\n\/********************************************************************************************\/\n\n\/*********************************************************************************************\n********           Timer0 for 1ms, F_CPU=8MHz, Prescaler 64, Top value=124         ***********\/\n\/*********************************************************************************************\/\nTCCR0|=(1&lt;&lt;WGM01)|(1&lt;&lt;CS01)|(1&lt;&lt;CS00); \/\/CTC mode2, prescaler 64\nTCNT0=0;                                \/\/Clear Timer\nOCR0=124;                               \/\/delay 1ms       \n\/*********************************************************************************************\/\nwhile(1)\n{\n  for(int i=0;i&lt;6;i++)\n\t{\t\n\t\tPORTC=0x3f;\n\t\tdelay_ms_1();\n\t\tPORTB=seven_segment(digits&#x5B;i]);\n\t\tPORTC&amp;=~(1&lt;&lt;i);\n\t\tdelay_ms_1();\n\t\tPORTC=0x3f;\n\t\tdelay_ms_1();\n\t\t\n\t}\n}\nreturn 0;\n}\n<\/pre><\/div>\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Digital-Clock.rar\" style=\"border-radius:10px;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download <\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-text-color has-link-color has-upper-heading-font-size wp-elements-a39ff1c4d2da2b5d25f6aa549aa729cc wp-block-paragraph\" style=\"color:#232323\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Digital-Clock.rar\">Digital Clock.rar<\/a><\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-fcb488ad913934c7161f56a82ef727df wp-block-paragraph\" style=\"color:#5c5c5c\">The clock we made is much more accurate. But for real time display we have a IC DS1307 for accurate measure of time. We will learn the interface in I<sup>2<\/sup>C section.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"590\" height=\"110\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/indus.png\" alt=\"\" class=\"wp-image-1624\" style=\"width:316px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/indus.png 590w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/indus-300x56.png 300w\" sizes=\"(max-width: 590px) 100vw, 590px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-6c5165aac23eac67e8da5c2a0df1ca54 wp-block-paragraph\" style=\"color:#5c5c5c\">Sometime it is need to shut down\/start any load in desire time. Suppose we want to shut down\/start a load after 2 hour. In that case the Timer comes into play. Now in that case we have to count second in reverse direction.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-ed489a61d59d98c8c8ce01ed613dc80b wp-block-paragraph\" style=\"color:#292929\">We can make an industrial relay in that-<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"138\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/function-1-2-1024x138.jpg\" alt=\"\" class=\"wp-image-1629\" style=\"width:683px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/function-1-2-1024x138.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/function-1-2-300x40.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/function-1-2-768x103.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/function-1-2.jpg 1351w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-0dff842e186a854ec4e5ffc82c2bee15 wp-block-paragraph\" style=\"color:#5c5c5c\">Enter your desire hour, minute and second in <strong>Clock selection switch<\/strong> than increment\/decrement in <strong>Increment switch\/Decrement switch<\/strong>. Finally press the <strong>Start<\/strong> switch to start the Timer. If load is on it will closed after counting stop. If load is off it will on after counting stop, during counting period the Pin4 switch will inactive.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Industrial-Load-controller.rar\" style=\"padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-text-color has-link-color has-upper-heading-font-size wp-elements-0b967cbe6263a4989b163df655f28579 wp-block-paragraph\" style=\"color:#212121\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Industrial-Load-controller.rar\">Download the .hex file using ATmega8 with proteus simulation<\/a><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s make a Digital Clock to display seconds, minute &amp; hour to seven segment displays. Here 6 seven segment display are used. We make it in 3 steps. First initial timer1 interrupt at 1s delay. In this project we use ATmega32 with external crystal with 8MHz at HFUSE=0x89 LFUSE=0xEF Timer1 interrupt with 1s counting In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-1599","post","type-post","status-publish","format-standard","hentry","category-timer-counter"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1599"}],"version-history":[{"count":23,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1599\/revisions"}],"predecessor-version":[{"id":2601,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1599\/revisions\/2601"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}