緒論
該項目的目標(biāo)是展示 HLS 在設(shè)計數(shù)字系統(tǒng)方面的能力。為此,本文展示如何在 HLS 中描述數(shù)字時鐘。
時鐘在 7 段數(shù)碼管上顯示小時、分鐘和秒。

它有兩種操作模式:時鐘和設(shè)置。時鐘模式是標(biāo)準(zhǔn)模式,在此模式下,當(dāng)前時間顯示在數(shù)碼管上。在設(shè)置模式下,可以使用按鈕設(shè)置時間。
下圖顯示開發(fā)板上的時鐘配置。

如下圖所示,該設(shè)計主要分為三個模塊:秒時鐘發(fā)生器、數(shù)字時鐘引擎和顯示驅(qū)動。

下面的流水線循環(huán)用于實(shí)現(xiàn)秒時鐘發(fā)生器。
booldelay(longlongintn){
#pragmaHLSINLINEoff
staticbooldummy=0;
for(longlongintj=0;j
數(shù)字時鐘引擎主要是跟蹤小時、分鐘和秒,并在收到來自秒時鐘發(fā)生器模塊的時鐘節(jié)拍時更新它們。以下代碼完成上訴功能。
voiddebounce(boolpulse,bool&out){
#pragmaHLSINLINEoff
staticboolout0=0;
staticboolout1=0;
staticboolout2=0;
staticboolstate=0;
if(state==0){
out2=out1;
out1=out0;
out0=pulse;
state=1;
}else{
delay(2500000);
state=0;
}
out=out0&out1&out2;
}
voidset_time(
ap_uint<6>&seconds,
ap_uint<6>&minutes,
ap_uint<5>&hours,
boolset_second,
boolset_minute,
boolset_hour)
{
//--------------------------------------------------
staticboolsecond_state=0;
if(second_state==0&&set_second==1){
seconds++;
if(seconds==60){
seconds=0;
}
second_state=1;
}
if(second_state==1&&set_second==0){
second_state=0;
}
//---------------------------------------------------
staticboolminute_state=0;
if(minute_state==0&&set_minute==1){
minutes++;
if(minutes==60){
minutes=0;
}
minute_state=1;
}
if(minute_state==1&&set_minute==0){
minute_state=0;
}
//----------------------------------------------------
staticboolhour_state=0;
if(hour_state==0&&set_hour==1){
hours++;
if(hours==24){
hours=0;
}
hour_state=1;
}
if(hour_state==1&&set_hour==0){
hour_state=0;
}
//----------------------------------------------------
}
voidclock_ticking(
ap_uint<5>&hours,
ap_uint<6>&minutes,
ap_uint<6>&seconds)
{
seconds++;
if(seconds==60){
seconds=0;
minutes++;
if(minutes==60){
minutes=0;
hours++;
if(hours==24)
hours=0;
}
}
}
voiddigital_clock(
boolset_time_sw,
bool&set_time_led,
boolset_second,
boolset_minute,
boolset_hour,
boolone_second_delay,
ap_uint<6>&seconds_out,
ap_uint<6>&minutes_out,
ap_uint<5>&hours_out
)
{
#pragmaHLSINTERFACEap_noneport=set_time_sw
#pragmaHLSINTERFACEap_noneport=set_time_led
#pragmaHLSINTERFACEap_noneport=set_minute
#pragmaHLSINTERFACEap_noneport=set_hour
#pragmaHLSINTERFACEap_noneport=seconds_out
#pragmaHLSINTERFACEap_noneport=minutes_out
#pragmaHLSINTERFACEap_noneport=hours_out
#pragmaHLSINTERFACEap_ctrl_noneport=return
staticap_uint<6>seconds=0;
staticap_uint<6>minutes=0;
staticap_uint<5>hours=0;
ap_uint<8>segment_data;
ap_uint<8>segment_enable;
staticboolstate_clock=0;
boolone_second=one_second_delay;
boolset_time_flag=set_time_sw;
if(one_second==1&&set_time_flag==0&&state_clock==0){
clock_ticking(hours,minutes,seconds);
state_clock=1;
}
if(one_second==0&&set_time_flag==0&&state_clock==1){
state_clock=0;
}
if(set_time_flag==1){
boolset_minute_debounce;
boolset_hour_debounce;
boolset_second_debounce;
debounce(set_minute,set_minute_debounce);
debounce(set_hour,set_hour_debounce);
debounce(set_second,set_second_debounce);
set_time(seconds,minutes,hours,set_second_debounce,set_minute_debounce,set_hour_debounce);
}
seconds_out=seconds;
minutes_out=minutes;
hours_out=hours;
set_time_led=set_time_sw;
}
最后一個 HLS 代碼在 7 段數(shù)碼管上顯示當(dāng)前時間。
#include
constap_uint<8>seven_segment_code[10]={
0b11000000,
0b11111001,
0b10100100,
0b10110000,
0b10011001,
0b10010010,
0b10000010,
0b11111000,
0b10000000,
0b10010000
};
booldelay(longlongintn){
#pragmaHLSINLINEoff
staticbooldummy=0;
for(longlongintj=0;jhours,
ap_uint<6>minutes,
ap_uint<6>seconds,
ap_uint<8>&seven_segment_data,
ap_uint<8>&seven_segment_enable)
{
#pragmaHLSINTERFACEap_noneport=hours
#pragmaHLSINTERFACEap_noneport=minutes
#pragmaHLSINTERFACEap_noneport=seconds
#pragmaHLSINTERFACEap_noneport=seven_segment_data
#pragmaHLSINTERFACEap_noneport=seven_segment_enable
#pragmaHLSINTERFACEap_ctrl_noneport=return
ap_uint<4>second_digit_1=seconds%10;
ap_uint<4>second_digit_2=seconds/10;
ap_uint<4>minute_digit_1=minutes%10;
ap_uint<4>minute_digit_2=minutes/10;
ap_uint<4>hours_digit_1=hours%10;
ap_uint<4>hours_digit_2=hours/10;
ap_uint<8>segment_data;
ap_uint<8>segment_enable;
staticap_uint<3>state=0;
switch(state){
//second
case0:
segment_data=seven_segment_code[second_digit_1];
segment_enable=0b11111110;
delay(250000L);
state=1;
break;
case1:
segment_data=seven_segment_code[second_digit_2];
segment_enable=0b11111101;
state=2;
delay(250000L);
break;
//minutes
case2:
segment_data=seven_segment_code[minute_digit_1];
segment_enable=0b11110111;
state=3;
delay(250000L);
break;
case3:
segment_data=seven_segment_code[minute_digit_2];
segment_enable=0b11101111;
state=4;
delay(250000L);
break;
//hours
case4:
segment_data=seven_segment_code[hours_digit_1];
segment_enable=0b10111111;
state=5;
delay(250000L);
break;
case5:
segment_data=seven_segment_code[hours_digit_2];
segment_enable=0b01111111;
state=0;
delay(250000L);
break;
default:
segment_data=seven_segment_code[0];
segment_enable=0b11111111;
state=0;
delay(250000L);
break;
}
seven_segment_data=segment_data;
seven_segment_enable=segment_enable;
}
綜合這些代碼后,使用 Vivado 工具將它們連接在一起并生成 FPGA 比特流。

對電路板編程后,可以看到下圖:

審核編輯:劉清
-
FPGA
+關(guān)注
關(guān)注
1652文章
22232瀏覽量
628572 -
數(shù)碼管
+關(guān)注
關(guān)注
32文章
1889瀏覽量
93577 -
時鐘發(fā)生器
+關(guān)注
關(guān)注
1文章
267瀏覽量
69807 -
數(shù)字時鐘
+關(guān)注
關(guān)注
2文章
153瀏覽量
21216 -
HLS
+關(guān)注
關(guān)注
1文章
133瀏覽量
25474
原文標(biāo)題:HLS 設(shè)計數(shù)字時鐘
文章出處:【微信號:Open_FPGA,微信公眾號:OpenFPGA】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
如何在Unified IDE中創(chuàng)建視覺庫HLS組件
如何在HLS 14.3中編寫pow功能?
合成中的Vivado HLS中的Pragma錯誤怎么解決
【正點(diǎn)原子FPGA連載】第一章HLS簡介-領(lǐng)航者ZYNQ之HLS 開發(fā)指南
數(shù)字時鐘設(shè)計功能描述
FPGA高層次綜合HLS之Vitis HLS知識庫簡析
使用Vitis HLS創(chuàng)建屬于自己的IP相關(guān)資料分享
Vivado環(huán)境下如何在IP Integrator中正確使用HLS IP
HLS系列–High Level Synthesis(HLS)的端口綜合2
FPGA設(shè)計中的HLS 工具應(yīng)用
關(guān)于Vivado HLS錯誤理解
如何在Vitis HLS中使用C語言代碼創(chuàng)建AXI4-Lite接口
HLS協(xié)議實(shí)現(xiàn)
如何在Vitis HLS GUI中使用庫函數(shù)?

如何在HLS中描述數(shù)字時鐘?
評論