Altera_Forum
Honored Contributor
15 years agoHelp with verilog code, calculator
Hello, i don't know if this is the correct place to put this post, if not, please move it!
I'm a newbie when it comes to programming in Verilog, I'm currently working on a final project for my class in school. I'm doing a calculator. This is not an advanced calculator, and its solved in a different way than what i think you normally do. Anyway, I'm using the DE2 board, and my problem is concerning the division.always@(negedge key3)
begin
div_summa1=((siffra1*10)+siffra2);
div_summa2=((siffra3*10)+siffra4);
if(div_summa1<1 | div_summa2<1)
begin
div_ental=0;
div_tiotal=0;
end
else if(div_summa1<10 & div_summa1>0 & div_summa2<10 & div_summa2>0)
div_ental=(div_summa1/div_summa2);
else
begin
if((div_summa1/div_summa2)<10)
div_ental=div_summa1/div_summa2;
else
begin
div_tiotal=(div_summa1/div_summa2)/10;
div_ental=(div_summa1/div_summa2)-(((div_summa1/div_summa2)/10)*10);
div_summa3=((((siffra1*10)+siffra2)/((siffra3*10)+siffra4))-((div_tiotal*10)+div_ental))*10+1;
end
end
endI think it might be hard to understand from this part of the code without much of an explanation but maybe you don't have to understand. I'm letting the user enter each numbers with 4 switches binary. And i convert it directly. So if you wanna enter 45... you enter a 4 binary first, which then directly gets converted to 4 decimal, and then i take it times 10 in the program and so on... I'm only using two digit numbers so they can never be bigger than 99. Anyway, the problem I'm having is that, when for example I want to take 45/2, I should get 22,5 ... but right now I'm only using integers. I'm simply wondering if there is ANY variable or whatsoever that can handle the decimals? Im trying to in some way pick it out and take 0.5*10 to get it into 5 which i can display later on as a decimal but i can't do that as long as i work with integers. Just ask if you wanna see the whole code, I've used Swedish names for the variables so it might be hard to understand, that's why i didn't post the whole code here. Thanks for your help! //Reckan