Sunday, September 5, 2010

Blog transferred

I aspire freedom. I adore my own identity.


I now blog in blog.punj.com.np


See you there folks !!


Monday, December 28, 2009

commands #2 feat. Windows

Let me continue the series

1]  scare your friends
this displays weird symbols, and no command line. clear won't work either
cat /dev/random
yes, ^C will quit the program but play with your friends with some innovative ideas
like, display the contents of /dev/random in 5 terminals at once. macabre feelings !!

2] save your packages
knew about this from rikil shah. save all your codecs and packages as an .iso file
APTonCD
try installing it
sudo apt-get install aptoncd
really helpful if you have to reinstall your whole linux again. you dont have to install your necessities all over again

3] backup your whole system
this is somewhat i have virtually tried. i tried remastersys, it took my 4 hours, but finally it said the file is too large. though i provided me some personal benefits, i would rather recommend  sbackup
click here, if you want to try remastersys
else try sbackup
credit: rikil

4] windows

I fear my friends won't read this post just because they love windows. So its for them
Wonderful 25 Windows Tricks
Greatest Windows Tips of All Time

Sunday, December 20, 2009

commands #1

i thought it would be nice if i put some commands that i have come across and have liked

1] cat and tac
you might have known by now, cat displays the file content.
tac ?
it displays in reverse

say a "file" has
a
b
c

then cat file prints
a
b
c

while tac file prints
c
b
a

2] uniq
it deletes the multiple entries. this is just a glimpse into this command. suppose you have a list of entries and you sort it. there can be more than one entry for the same value and you want to delete such multiple entries

echo filename|sort -n|uniq #sort -n sorts by name

3] rename
this is by far a very useful command. go for it. i just want to give a small trailer.
say, you are near your final assignment and you have notes [ya, digital notes] from all your friends. but you want to organize all these files into one directory with the name of person who gave you the files in the front

suppose i have you 7 files, logic1.pdf, logic2.pdf ..logic7.pdf
then you want it as
punj_logic1.pdf....punj_logic7.pdf
then in the directory which has only these files, the command is

rename 's/^/punj_/' *
^ means to append punj_ in the front
s means to substitute
it has numerous applications. just have a try

Friday, December 18, 2009

verilog in linux


if you dont want to switch to windows just for verilog, then here are some steps
i have used icarus verilog with gtkwave for waveforms
1] install icarus verilog
sudo apt-get install icarus

2]the compiler is installed. its just that easy

3 install another software so that you can see the waveforms
sudo apt-get install gtkwave

4] write a program for verilog. well,with a module and a testbench on it. i use gvim for that.
as an example, i have used decoder4x1
gvim decoder4x1.v

5]don't forget to write these lines in your testbench so that you can view the output waveforms
$dumpfile("check.vcd");
$dumpvars(0,decoder_tb);


where, check.vcd is the output waveform file
decoder_tb is the testbench name

6] once you have written and saved, you need to compile it. for that
iverilog decoder4x1.v -o decoder
then, decoder becomes the object file

7]run the object file
vvp decoder
you get something like in the picture shown
see that the file check.vcd is also opened for output

8] watch your waveform
gtkwave check.vcd

9] just insert your objects and watch the waveforms

well, it may seem long, but its really efficient and easy. just you need to get into the groove
though, today i finally found the link for modelsim in linux. will let you know once i am able to use it.

Tuesday, December 15, 2009

divide by 5 counter


this is divide by 5 counter with little tweaking from divide by 3 counter. just find the condition for t[1:0]

module by5(clk,op);
input clk;
output reg op;
reg[1:0] t;
reg [2:0]q;
initial
begin
op <= 1'b0;
q <= 3'b0;
t <= 2'b0;

end
always @ (negedge clk) begin
if (q<3'b100) begin //this differs from by3 counter
q<=(q+1);
end else begin
q<=0;
end
end


always @ (posedge clk) begin

if (~q[0] & q[1] & ~q[2])
t[1]<=~t[1];
end
always @ (negedge clk) begin
if (~q[0] & ~q[1] & q[2])
t[0]<=~t[0];
end

always @ (t) begin
op<= (t[0]^t[1]);
end

endmodule

module by5_tb; //testbench
reg clk;
wire op;
by5 test_bench(clk,op);
always
#1 clk = ~clk;
initial
begin
clk=1'b0;
#50 $finish;
end
initial
begin
$display("time\t\top");
$monitor("%g\t%b",$time,op);
end
initial
begin
$dumpfile("waveby5.vcd");
$dumpvars(0,by5_tb);
end
endmodule

divide by 3 counter_hardware synthesized


well, in my previous post i have uploaded divide by n counter
it works perfectly if you have to simulate it and show it to your teacher. but the fact is that it is not advisable for hardware synthesis because i have used always @ (clk) which means it works on both positive and negative edge triggering of clock, which is unusual for a chip
so this is my divide by 3 counter

module by3(clk,op);
input clk;
output reg op;
reg[1:0] q,t;
initial
begin
op <= 1'b0;
q <= 2'b0;
t <= 2'b0;

end
always @ (negedge clk) begin //for 3-up counter
if (q<2'b10) begin
q<=(q+1);
end else begin
q<=0;
end
end


always @ (posedge clk) begin
//to differentiate the upgoing and downgoing signals so that i can separate
// divide by 3 divides the frequency in both upgoing and downgoing pulse. so this is for upgoing pulse
if (q[0] & ~q[1])
t[1]<=~t[1];
end
always @ (negedge clk) begin //for downgoing pulse
if (~q[0] & q[1])
t[0]<=~t[0];
end

always @ (t) begin
op<= (t[0]^t[1]);
end

endmodule

module by3_tb; //testbench
reg clk;
wire op;
by3 test_bench(clk,op);
always
#1 clk = ~clk;
initial
begin
clk=1'b0;
#50 $finish;
end
initial
begin
$display("time\t\top");
$monitor("%g\t%b",$time,op);
end
initial
begin
$dumpfile("waveby3.vcd");
$dumpvars(0,by3_tb);
end
endmodule

Saturday, November 21, 2009

virtual FM tuner using shell scripting

this is the virtual fm tuner.
simple shell scripting
but, be connected to the internet
till now, i have just added Nepali FMS.
and, obviously thanks to Satyendra Raj Pandey for this FM idea.

to download the file click here

else, the code is here

#! /bin/sh
commonCommand()
{
common1='[playlist]'
common2='NumberOfEntries=1'
}
quit ()
{
clear
echo "*************************"
printf "SIMPLE FM TUNER V1.0\nDeveloped by\nPUNJ POKHAREL\npunj33@gmail.com\npunj33.blogspot.com\n*************************\n\n"
printf "\nPlease feel free to edit, distribute and contribute. Its totally open source\n\n"
printf "It can be made a whole lot better. So, share your ideas\n\n"
echo "THANK YOU FOR USING SIMPLE FM TUNER V1.0"
printf "\n\n"
echo "Press any Enter to exit"
read nothing
# i tried to kill extracting PID but kill the whole totem seems easy
# a=`ps -ef|grep 'totem fm.log'|grep -v 'grep'`
# b=`echo $a|awk '{print $3}'
# kill -9 totem

if [ $counter -ge 1 ]
then
killall vlc 2> /dev/null
else
killall totem 2> /dev/null
fi
clear
break;
}
choose()
{
case $choice in
1)fm='File1=http://67.202.67.18:8208/;stream.mp3ls';;
2)fm='File1=mms://64.62.166.162/hitsfm';;
3)fm='File1=mms://64.62.166.162/ujyaalofm';;
4)fm='File1=mms://64.62.166.162/sagarmatha_fm' ;;
5)fm='File1=mms://64.62.166.162/nepalfm' ;;
6)fm='File1=mms://64.62.166.162/maitrifm';;
7)quit ;;
esac
}
tune()
{
printf "$common1\n$common2\n$fm" > fm.log
counter=`whatis cvlc|grep 1|wc -l`
if [ $counter -ge 1 ]
then
killall vlc 2> /dev/null &
cvlc fm.log 2> /dev/null &
else
totem fm.log 2> /dev/null &
fi
printf "TUNING "
for i in 1 2 3 4 5
do
printf "."
sleep 0.255
done
echo
}
while [ 0 ]
do
clear
printf "********Welcome to a SIMPLE FM TUNER V1.0*********\n\n"
echo "Please enter your FM station. Press its symbol no. correctly \n"
printf "1. Kantipur FM \n2. Hits FM\n3. Ujjyalo FM\n4. Sagarmatha FM\n5. Nepal FM \n6. Maitri FM\n7. Quit\n\n"

read choice
if [ $choice -ge 8 ]
then
echo "WRONG CHOICE YOU MORON"
echo "Press any key to continue"
read nothing123
else

commonCommand
choose
tune
fi
done