Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

an operation in C++ to VHDL

Status
Not open for further replies.

Cutey

Member level 2
Joined
Nov 6, 2009
Messages
51
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,607
Hi ppl
How I translate the following operation in C++ to the same operation in VHDL

for A=2; A<n ; A++

without using ( for ) operation in VHDL
 

how are you doing it in C?

1.) you are creating some basic memory structure for "A".
2.) you are creating a state machine with the states:
init: A = 2
check: is A < n?
perform: A = A + 1
done/idle:

The easiest way to implement this in HDL would be to do the same thing: create a state machine with 4 states "idle", "init", "check", and "perform", where idle can transition to init, init to check, check to perform, check to idle (if A = n), and perform to check. now create a structure for A such that if state = init, A =2, if perform, A = A + 1.

This isn't the most efficient code -- just as the software might be optimized, you might be able to find a way to optimize the hardware. possibly to remove some states, and possibly to share some registers. in the above case, "idle" and "init" might be combined, and "check" and "perform" might be combined.
 

Take care that loops with a variable end like the case in here are not synthesizable.
--
Amr
 

The best thing to do is to learn digital logic design first. C++ to VHDL translation is not as simple as translating it from one language to another. Besides, C++ is a programming language, VHDL and Verilog are not. They are hardware description languages. You first have to work out what the hardware is before you can describe it.
 

I would approach this with an FSM.

Idle State -> Wait for input n to be valid and register it, move to the compute state
Compute State -> Have a counter that counts from 0 to n-2 (or 2 to n...whatever), incrementing the counter each clock cycle. After each iteration, compare with n. If equal to n then move back to the idle state


As Trick****y said, C++ to VHDL is not simple. It takes an understanding of how digital logic and FPGAs work. You must think about how the code will synthesize rather than if it will work. Software languages are a lot easier to work with since you do not have to concern yourself as much as to how simple things like loops work.

Good luck
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top