Tuesday, August 30, 2011

Serial Servo Controller

So , your search for serial servo controller should stop at this point
Take my word i have GOOGLED it for 2years

1) The most famous and popular Serial Servo Controller ( SSC32) open source project from lynxmotion
Uses Atmega and Serial to Parallel converter IC's to control Servo's with 1us resoltion
written in C , pulse width 0 - 65000 us ( which is not at all needed for controlling servos) ,
GUI interface and Control Terminals Available

2) mcu labs SSX32 Serial Servo Controller
PIC based , no extra Hardware needed , pulse width 500 to 2500 , 50% less cost compared to lynxmotion SSC32 , don't know the correct crystal speed but should be greater than 16Mhz ,
didn't find any GUI Application , should use it like an AT Modem

3) My favorite and inspiration 16 channel serial servo controller
AVR based , Poor resolution written in assembly language

There are other versions of SSC32 with 8 and 16 channels

That's as simple as it gets , personally i haven't used any of these but $20 / $40 is a little too much for me to digest

A Though cant we can Control all 32 servos without any hardware with Atmega8 ( 130INR ) or Atmega32 ( 250INR ) ,

Indian Made Serial Servo Controller - not compromising on
Resolution - 1us
No Extra Hardware apart for crystal , Caps
variable Pulse width's
GUI Interface
Group Moves and much more

That's where i am headed to , in short all the feature from SSC32 on a single chip without any need for extra Hardware

i tried to build it a year ago , that was my final year project !
my servo controller aka final year project had 255 steps with 7us resolution wrapped around a scheduler with GUI interface written in VB
Because of its poor resolution it has failed to pass all basic test's and more over servo used to shake from Kashmir to kanyakumari , some how i got Excellent Grade for my project
there ends the story

Today after 18months I Got an Idea to implement this IMSSC ( Indian Made Serial Servo Controller ) and succeeded in optimizing CODE for 1us resolution ,
i will be posting the details and the success story in my next blog

till then happy coding
Nataraja G



Sunday, August 21, 2011

My First Android App

Hello bloggers , after 2hrs of Java Tutorial from my brother ( @ http://gadikotamohan.blogspot.com/ ) i have created my first Android App

here it goes , Its very easy to understand and to program guess that's why its so popular
There are lot of things to do before you can start writing Android App
Download eclipse IDE , android SDK , integrated android emulator and various setting
i am not going through all these things google about'em and find it yourself

Here are the problem's which i encountered
1) The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new OnClickListener(){})

in your code include
import android.view.View.OnClickListener;

else DialogInterface.OnClickListener would be assumed as the method
and remove import statement for DialogInterfaces

2) andorid" for attribute "andorid:name" associated with an element type "activity" is not bound.

while typing in a new activity name in AndriodManifest.xml , this error's might bug you
dont worry , it a TYPO :)
andorid" for attribute "andorid:name" associated with an element type "activity" is not bound.

It should be android , that's all about the errors

now the Android App

screenshot of android emulator ( what's more emulator can access internet , aint a dumb simulator )















Home screen showing the App which i have created














launch button which invokes another activity















second activity called successfully , i have added few text boxes to check the layout xml file
its is easier that VB.NET !! take my word for it















That's it nothing HIGH FI about the App , happy coding
FYI one of my friend has asked to develop a App which can record call's , after googling found that the developer's haven't considered this as it may cause legal issues in some countries


codes
:

package nataraja.helloworld;

import android.app.Activity;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class HelloworldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnSimple = (Button) findViewById(R.id.btnSimple);
btnSimple.setOnClickListener (new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent (v.getContext(), activity2.class );
startActivityForResult(intent,0);
}
}) ;
}

}


activity2 class :

package nataraja.helloworld;

import android.app.Activity;
import android.os.Bundle;

public class activity2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
}
}

Sunday, June 20, 2010

Matlab VB communication

i use Matlab for image processing abd VB for speech recognition
this code makes communication between VB and matlab
VB passes parameter's to Matlab and return's code back to calling application


Module Module1
Sub Main()
Dim MatLab As Object ' Create Object variable
Dim Result As String ' Create String variable
Dim lngLen As String

' Either way below will work.
MatLab = CreateObject("Matlab.Application")
MatLab.Execute("enableservice('automationserver',true)")

MatLab.Visible = False ' Hide MATLAB application

'Calling m-file from VB
Result = MatLab.Execute("cd F:\My Documents\MATLAB")
Result = MatLab.Execute("VBtesting(1)") 'passing value to VBtesting.m
lngLen = Len(Result)
MsgBox(Result)
MsgBox(lngLen)
Result = Mid$(Result, 14, 1) ' storing the result from Matlab
MsgBox(Result) ' display the returned value
MsgBox("VBtesting(" & Result & ")") 'passing the received value to VBtesting.m
Result = MatLab.Execute("VBtesting(" & Result & ")")
MsgBox(Result) ' display

End Sub

End Module


code for VBtesting1.m

function p=VBtesting1(a)
tic
load('abc.mat','ao');
toc
tic
if a==1
t = linspace(0,2*pi,16000);
y = sin(500*t);
y1 = sin(800*t);
else
t = linspace(0,2*pi,4000);
y = sin(200*t);
y1 = sin(400*t);
end
putdata(ao, [y' y']);
putdata(ao, [y1' y1']);
set(ao, 'TriggerType', 'Immediate');
toc
start(ao);
wait(ao,5);
p=ceil(rand(1,1)*10);


this code creates different audio signals depending on value's passed to function

thus we can have a bidirectional communication between both

Thursday, December 10, 2009

Verilog code's

bidirectional buffer
module bidirectionalbuffer(A,B,C,sel);
inout [7:0]A; //bus
input [7:0]B; //tx
output [7:0]C; //rx
input [2:0]sel;


genvar j;
generate for(j=0;j<8;j=j+1) begin :buffif_loop1
bufif1 m1 (B[j],A[j],sel[0]);// bus to tx
bufif1 m2 (A[j],C[j],sel[1]); // rx to bus
end
endgenerate
endmodule


timing diagram

UART Verilog code with testbench

reference www.asic-world.com
module uart2 (
reset ,
txclk ,
ld_tx_data ,
tx_data ,
tx_enable ,
tx_out ,
tx_empty ,
rxclk ,
uld_rx_data ,
rx_data ,
rx_enable ,
rx_in ,
rx_empty
);
// Port declarations
input reset ;
input txclk ;
input ld_tx_data ;
input [7:0] tx_data ;
input tx_enable ;
output tx_out ;
output tx_empty ;
input rxclk ;
input uld_rx_data ;
output [7:0] rx_data ;
input rx_enable ;
input rx_in ;
output rx_empty ;
wire rx_in;

assign rx_in=tx_out ; // connect receiver to transmitter interconnect
assign uld_rx_data=~rx_empty; // unload data when rx buffer is full
// Internal Variables
reg [7:0] tx_reg ;
reg tx_empty ;
reg tx_over_run ;
reg [3:0] tx_cnt ;
reg tx_out ;
reg [7:0] rx_reg ;
reg [7:0] rx_data ;
reg [3:0] rx_sample_cnt ;
reg [3:0] rx_cnt ;
reg rx_frame_err ;
reg rx_over_run ;
reg rx_empty ;
reg rx_d1 ;
reg rx_d2 ;
reg rx_busy ;

// UART RX Logic
always @ (posedge rxclk or posedge reset)
if (reset) begin
rx_reg <= 0;
rx_data <= 0;
rx_sample_cnt <= 0;
rx_cnt <= 0;
rx_frame_err <= 0;
rx_over_run <= 0;
rx_empty <= 1;
rx_d1 <= 1;
rx_d2 <= 1;
rx_busy <= 0;
end else begin
// Synchronize the asynch signal
rx_d1 <= rx_in;
rx_d2 <= rx_d1;
// Uload the rx data
if (uld_rx_data) begin
rx_data <= rx_reg;
rx_empty <= 1;
end
// Receive data only when rx is enabled
if (rx_enable) begin
// Check if just received start of frame
if (!rx_busy && !rx_d2) begin
rx_busy <= 1;
rx_sample_cnt <= 1;
rx_cnt <= 0;
end
// Start of frame detected, Proceed with rest of data
if (rx_busy) begin
rx_sample_cnt <= rx_sample_cnt + 1;
// Logic to sample at middle of data
if (rx_sample_cnt == 7) begin
if ((rx_d2 == 1) && (rx_cnt == 0)) begin
rx_busy <= 0;
end else begin
rx_cnt <= rx_cnt + 1;
// Start storing the rx data
if (rx_cnt > 0 && rx_cnt < 9) begin
rx_reg[rx_cnt - 1] <= rx_d2;
end
if (rx_cnt == 9) begin
rx_busy <= 0;
// Check if End of frame received correctly
if (rx_d2 == 0) begin
rx_frame_err <= 1;
end else begin
rx_empty <= 0;
rx_frame_err <= 0;
// Check if last rx data was not unloaded,
rx_over_run <= (rx_empty) ? 0 : 1;
end
end
end
end
end
end
if (!rx_enable) begin
rx_busy <= 0;
end
end

// UART TX Logic
always @ (posedge txclk or posedge reset)
if (reset) begin
tx_reg <= 0;
tx_empty <= 1;
tx_over_run <= 0;
tx_out <= 1;
tx_cnt <= 0;
end else begin
if (ld_tx_data) begin
if (!tx_empty) begin
tx_over_run <= 0;
end else begin
tx_reg <= tx_data;
tx_empty <= 0;
end
end
if (tx_enable && !tx_empty) begin
tx_cnt <= tx_cnt + 1;
if (tx_cnt == 0) begin
tx_out <= 0;
end
if (tx_cnt > 0 && tx_cnt < 9) begin
tx_out <= tx_reg[tx_cnt -1];
end
if (tx_cnt == 9) begin
tx_out <= 1;
tx_cnt <= 0;
tx_empty <= 1;
end
end
if (!tx_enable) begin
tx_cnt <= 0;
end
end

endmodule
downloadclick

test bench for the above
module uartcontroller(data,load,unload,rxen,txem,rxem,txen,reset,rxin,txout,clkL,clkH);
inout [7:0]data;
output load;
output clkL,clkH;
output unload;
output rxen;
output txen;
output reset;
input txem,rxem;
reg txemt;
reg rxemt;
output txout;
input rxin;
reg clkL,clkH;
wire rxen,txen;
reg reset;
wire [2:0]sel;
wire [7:0]datain,dataout;
uart m1(
.reset(reset) ,
.txclk(clkH) ,
.ld_tx_data(load) ,
.tx_data(datain) ,
.tx_enable(txen) ,
.tx_out(txout) ,
.tx_empty(txem) ,
.rxclk(clkL) ,
.uld_rx_data(unload) ,
.rx_data(dataout) ,
.rx_enable(rxen) ,
.rx_in(rxin) ,
.rx_empty(rxem)
);
assign rxin=txout;
assign sel[0]=load;
assign sel[1]=unload;
bidirectionalbuffer m2(.A(data),.B(datain),.C(dataout),.sel(sel)); // using same data lines for loading data into tx register and reading data from rx buffer
initial begin
clkL<=1'b0;
clkH<=1'b0;
reset<=1;
#10 reset <=0;
end
// clock generation
always
#10 clkL<=~clkL; // clock for rx

always
#160 clkH<=~clkH; // clock for tx
endmodule




happy coding

Neural Network's Matlab

using NNTOOL
here we will be training a network to recognize a particular pattern
first we have to normalize the data.......
let the data be (X)
2 5 6 3 1
5 2 2 5 1
4 4 5 4 4
1 5 2 4 5
1 6 6 6 6
3 6 3 2 1
6 4 2 5 4
3 1 2 5 3
4 1 4 3 1
2 2 3 4 3

each column a particular pattern
first find the minimum value from each column and subtract
the same then divide the whole column with the max value (column)
ull get data something like this (x=rand(10,5))

0.5822 0.5447 0.4046 0.6963 0.3477
0.5407 0.6473 0.4484 0.0938 0.1500
0.8699 0.5439 0.3658 0.5254 0.5861
0.2648 0.7210 0.7635 0.5303 0.2621
0.3181 0.5225 0.6279 0.8611 0.0445
0.1192 0.9937 0.7720 0.4849 0.7549
0.9398 0.2187 0.9329 0.3935 0.2428
0.6456 0.1058 0.9727 0.6714 0.4424
0.4795 0.1097 0.1920 0.7413 0.6878
0.6393 0.0636 0.1389 0.5201 0.3592



let the output of each pattern be(y=rand(1,5))
0.7363 0.3947 0.6834 0.7040 0.4423
output corresponding to each column,normalized
x(:,1)-->y(1,1)
x(:,2)-->y(1,2) lly

type nntool at matlab command window another window named
Network/Data Manager will pop up



click on import button and export x as input data and y as target data !

ull get a message like this


after this close import window ,now ur network/data manager window will look like this

now click on new button ull see another window here u have to select the type of NN u want to create
we will be create a feedforward back propagation NN most popular one
der u select the inputs and target data


then click on create and close that window
now u should be able to see a network in network/data manager window(middle)
click on that newly created network (icon) then click on open
ull see another window


click on train tab -> then training info
add inputs and targets as x,y then click on train network ....wait for some time ull see a graph once the
goal is met click on stop training button and close that graph and this window ..
now our NN is trained and is read for testing ........ hurray
after this click on export button in network/data manager ....
now close this window ..u should be able to see ur trained network in ur matlab work space......

now use this command
output=sim("networkname","data")
example
output=sim(network1,x(:,1))
which should be same as y(1,1)
u can test ur network reliability by adding noise .....
ur rand function for this purpose

thats it ........
thks

Sunday, November 29, 2009

Scrolling message display board

To make an led ON/OFF we usually use one I/O pin of the microcontroller
this will work fine with 5 to 8 leds but when u have drive a display board
which may contain LEDs between 70 to 100 depending on the matrix size , using each microcontroller I/O to control each LED is impossible and !!!!!!!!

so there are ways in which we can control many leds using few i/o pins
1)using charlieplexing if we have n i/o pins we can control
n*(n-1) leds using this method and all the pattern's may not be possible in this case
more about charlieplexing can be found at charlieplexing

charlieplexing with 3 i/o pins



2)using Dot Matrix
leds a connected like this


two types common anode n common cathode type.....
u can buy this modules , they cost around Rs70(5*7 matrix)


here we send data row wise , that is activating one row at a time and through column we need to send the data which we want to see
this image might give a better idea


i have shown for two row's this repeat's in a loop for all the row ..

3) using decoder's this is the ultimate way and flickering can be seen if the microcontroller is working at slow speed's , we can control 1024 leds with 11 i/o pins two 5*32 decoder for row n column
we are not interested with this method , as modules are not available we need solder the whole LED network

Program which i have implemented
ATmega32 chip running @4mhz
compiler WINAVR

#include
#define F_CPU 4000000UL
#include
typedef unsigned char u8;
typedef unsigned int u16;

int main(void)
{
u16 data2[5]={1,2,4,8,16},y[5];
u16 i,j,k,p,t,l[5][6]={{0x7f,0x41,0x41,0x41,0x3e,0x00},{0x3e,0x41,0x41,0x41,0x3e,0x00},{0x7f,0x40,0x40,0x40,0x40,0x00},{0x7f,0x40,0x40,0x40,0x40,0x00},{0x01,0x02,0x7c,0x02,0x01,0x00}};//data to be displayed
DDRD=0X00; //control i/p for Lb and Rb
PORTD=0XFF; //internal pull ups
DDRA=0xff;//data O/p to dot matrix
DDRC=0xff; //control o/p to dot matrix
for(i=0;i<5;i++)
{
y[i]=0;
}

while(1)
{
for(i=0;i<5;i++)
{
for(p=0;p<6;p++)
{
// display data
for(j=0;j<50;j++)
{
for(k=0;k<5;k++)
{
PORTC=data2[4-k];
PORTA=y[k];

_delay_ms(1);

}
}
// next loop data
for(t=0;t<4;t++)
{
y[4-t]=y[3-t];
}

y[0]=l[i][p];//new data

}// end of p for

}// end of i for
}// end while

}

here's the vedio moving message vedio

PING PONG game on DOT matrix