cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
deepa_krishna
Observer
Observer
2,975 Views
Registered: ‎08-09-2016

DATA TYPE for 4 bit counter in Vivado HLS

Jump to solution

hi pals,

 

This is a program for 8-bit parallel counter

 

typedef unsigned char u8;

void counter(volatile bool run, volatile int delay, volatile u8 *counter) {
#pragma HLS INTERFACE ap_none register port=counter
#pragma HLS INTERFACE ap_none register port=delay
#pragma HLS INTERFACE ap_none register port=run
#pragma HLS RESOURCE variable=delay core=AXI4LiteS metadata="-bus_bundle CONTROL_BUS"
#pragma HLS RESOURCE variable=return core=AXI4LiteS metadata="-bus_bundle CONTROL_BUS"

volatile u8 counter_reg = 0;

while(run == 1) {
volatile int i = 0;
for (i = 0; i < delay; i++);
*counter = counter_reg++;
}
}

 

Which data type should I use to make it 4-bit parallel counter?

 

Best Regards,

Deepa krishnamurthy

0 Kudos
Reply
1 Solution

Accepted Solutions
u4223374
Advisor
Advisor
5,018 Views
Registered: ‎04-26-2015

There's no built-in C type that's 4 bits long, so you'll need to have a look at UG902 v2016.4, page 207 ("Arbitrary Precision Data Types Library"). Otherwise you could explicitly overflow the 8-bit counter when it reaches 16.

View solution in original post

4 Replies
u4223374
Advisor
Advisor
5,019 Views
Registered: ‎04-26-2015

There's no built-in C type that's 4 bits long, so you'll need to have a look at UG902 v2016.4, page 207 ("Arbitrary Precision Data Types Library"). Otherwise you could explicitly overflow the 8-bit counter when it reaches 16.

View solution in original post

muzaffer
Teacher
Teacher
2,947 Views
Registered: ‎03-31-2012

@deepa_krishna if you code your counter like this counter = (counter + 1) & 0xf, I am pretty sure the logic optimization will come out to a 4 bit variable.

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Reply
deepa_krishna
Observer
Observer
2,907 Views
Registered: ‎08-09-2016

Thanks for the solution

0 Kudos
Reply
deepa_krishna
Observer
Observer
2,906 Views
Registered: ‎08-09-2016
I tried masking the bits.. but the ports were still 8bits.


0 Kudos
Reply