Mohammad Hosseinabady
Published © MIT

Floating-Point Numbers on 7-Segment Display in HLS

This mini-project shows how to display a floating-point number on 7-segments using C/C++ HLS.

BeginnerProtip1 hour13
Floating-Point Numbers on 7-Segment Display in HLS

Things used in this project

Hardware components

Basys 3
Digilent Basys 3
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Vivado Design Suite HLx Editions
Xilinx Vivado Design Suite HLx Editions

Story

Read more

Code

Code snippet #1

Plain text
bool delay(int n) {
#pragma HLS INLINE off
  static bool dummy = 0;
  for ( int i = 0; i < n; i++) {
    for ( int j = 0; j < n; j++) {
#pragma HLS pipeline
      dummy = !dummy;
     }
  }
  return dummy;
}

Code snippet #2

Plain text
void display_driver(
  ap_uint<4> a, ap_uint<4> b, ap_uint<4> c, ap_uint<4> d,
  ap_uint<8> &segment_data,
  ap_uint<4> &segment_enable,
  bool       reset) 
{
  static ap_uint<2> state = 0;
  while(reset == 0) {
    switch (state) {
    case 0:
      segment_data   = svn_sg_code[a];
      segment_enable = 0b0111;
      state = 1;
      delay(500);
      break;
    case 1:
      segment_data   = svn_sg_code[b] & 0b01111111; 
      segment_enable = 0b1011;
      state = 2;
      delay(500);
      break;
    case 2:
      segment_data   = svn_sg_code[c];
      segment_enable = 0b1101;
      state = 3;
      delay(500);
      break;
    case 3:
      segment_data   = svn_sg_code[d];
      segment_enable = 0b1110;
      state = 0;
      delay(500);
      break;
  }
}
}

Code snippet #3

Plain text
void  display_float(
  ap_uint<8> &segment_data,
  ap_uint<4> &segment_enable,
  bool        reset) {
#pragma HLS INTERFACE ap_none port=segment_data
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS INTERFACE ap_none port=segment_enable
#pragma HLS INTERFACE ap_none port=reset

  float a = 23.45;
  unsigned int a_int = a;
  float b = a - a_int;

  unsigned int a_int0 = a_int%10;
  a_int = a_int /10;
  unsigned int a_int1 = a_int%10;

  unsigned int b_int0 = b*10;
  b = b*10 - b_int0;
  unsigned int b_int1 = b*10;

  display_driver(a_int1, a_int0, b_int0, b_int1, segment_data,  
  segment_enable, reset);
}

Credits

Mohammad Hosseinabady

Mohammad Hosseinabady

3 projects • 1 follower
Mohammad Hosseinabady has a PhD degree in Computer and Electronics Engineering. He is an expert in High-Level Synthesis for FPGAs.

Comments

Add projectSign up / Login