Discussion in "ARM Development" started by    hbaocr    Jan 30, 2008.
Wed Jan 30 2008, 05:09 pm
#1
hey,LPC2214 seems not to support counter using external CLK.It only has timer counter /and capature pin.so , how can I read speed of DC motor by encoder using LPC2214.
Wed Jan 30 2008, 11:17 pm
#2
how bout using an IR style encoder? with black and white dial on the motor.. black will not reflect where as white will reflect.. use interrupt pin of ARM to count... whenever interrupt occurs increase the rotation count by 1
Thu Jan 31 2008, 01:21 am
#3
i guess u are using an ENCODER (may be quad phased kinda...)
i guess you have been using an encoder to counter circuit... forget it at the moment u n wont need it now...
well the encoder normally gives data in GRAY code format...
ex..
00
01
11
10 for clockwise...
and
00
10
11
01 for anticlock wise..
now interface the o/p of your encoder to the mCU pins ex. P0.20,P0.21
now what is the max RPM for ur encoder???
accordingly nake an ISR based on timer say timer0.
now check status of tour pin in the ISR u will find it in accordance with one of the above sequence...
change the direction and data will be in accordance with the other sequence... first check this thing practically by now u wud get the direction of rotation then we will go for the amount of rotation


[ Edited Thu Jan 31 2008, 01:48 am ]
Thu Jan 31 2008, 05:56 am
#4
thank for your helping, But I'm using incremental ENCODER 100 pulse/rorate.
Thu Jan 31 2008, 11:49 am
#5
well that is what i said u r using an encoder .....

now tell me how many output line s u have from the encoder .... or give us some idea about youy encoder..!! serial no. model no. manufacturere etc...
Thu Jan 31 2008, 12:03 pm
#6
here my code
#include <LPC22xx.H>
 										// LPC2214 MPU Register
#include <stdio.h>
											// For Used Function printf 
void Delay(unsigned long int count1);
void outs(unsigned int datlong, unsigned int *p);
extern void init_serial0 (void);							// Used Initial UART0 From "Serial0.c"
//CCLK=12xM=12x5=60MHZ
//PCLK=CCLK (VPBDIV=0x00)
void IRQ_Match0_timer0(void)__irq;//ngat Timer0
void IRQ_Read_Encoder(void)__irq; //ngat ngoai de doc encoder
//================ham chinh==========================
unsigned int  pulse_count=0;
unsigned int  vantoc,c,count=3500;
unsigned int  w[3500];
int main(void)
{ 
PINSEL1=0x15400001;
init_serial0();				   							// Initial UART0 = 9600,N,8,1
//int timer0
T0TCR=0x2;//TC and PR count disable
T0PR=59;//tan so dem cua TC = PCLK/(PR+1)=1MHz->
 1us increase 1 unit of timer counter
T0MCR=0x3;//interrupt match0 enable and TC reset when match , va giu TC ko dem cho toi khi bit 1 bang 0
T0MR0=1000;//1ms for TC reaches to T0MR0 and occur match0
//++++++++++++++EINT0 doc encoder+++++++++++++++++++
EXTMODE=1<<0;//ngat canh EINT0
EXTPOLAR=1<<0;//td canh len
//interrupt
VICVectCntl0=0x2E;//choose Source EINT0=14, and enable IRQ slot
VICVectAddr0=(unsigned)IRQ_Read_Encoder;

VICVectCntl1=0x24;//choose Source Int Timer0=4, and enable IRQ slot
VICVectAddr1=(unsigned)	IRQ_Match0_timer0;

VICIntEnable=(1<<4)|(1<<14);//enable EXINT0 ,Timer0 interrupt source
//T0TCR=0x1;//cho phep TC dem
printf("wait for a moment and turn on motor");
while(1)
{  
   ;
   
} 
  
}
//=====================end main=======================
//==============interupt function=============
 void IRQ_Match0_timer0(void)__irq
{
	
	if(c<=count)
	{
	w[c] =	pulse_count;
	c++	 ;
	//pulse_count=0;//reset bo dem
	}
	else
	{
	 c=0;
	 outs(count,w);
	 while(1);
	 
	 }
	T0IR=1;  //xoa co ngat MR0 de cho match0 tiep theo xay ra
	VICVectAddr = 0x00000000;	// Reset Global Interrupt and return

}

//==============end interrupt===========
void IRQ_Read_Encoder(void)__irq
{
	if (c<=0)
	{
	T0TCR=0x1;//cho phep TC dem
	}
pulse_count++;
EXTINT|=0x1;
VICVectAddr = 0x00000000;	// Reset Global Interrupt and return
}


//xuat port
void outs(unsigned int datlong, unsigned int *p)
{
unsigned int t,d,k;
k=1;
for(t=0;t<datlong;t++)
{
p++;
d=*p;
printf("%u , ",d);
Delay(100);
}
}


void Delay(unsigned long int count1)
{
unsigned long int i,k;
k=count1*5200;
  for(i=0;i<k;i++);	// Loop Decrease Counter	
}


[ Edited Thu Jan 31 2008, 04:45 pm ]
Thu Jan 31 2008, 12:13 pm
#7
my DC motor made by Hitachi Ltd from Japan.
here are somes infos about it :
Power : 21 W
Volt :24V
ENCODER :100P/R
type : D04321E
Beside 2 Wrie to supply Power to DC motor . It also have 4 another WIREs for Encoder.
Red WIRE :for VCC=5V
Green WIRE for GND
WHITE WIRE for Pulse A output
Yello WIRE for pulse B output

In my project I connect pulse A to External interrupt 0 pin of microcontroller
Thu Jan 31 2008, 01:47 pm
#8

WHITE WIRE for Pulse A output
Yello WIRE for pulse B output

In my project I connect pulse A to External interrupt 0 pin of microcontroller



there u are...
even i am using the same encoder!!!!!1

if u check status of the above two wires and monitor it for some time u will find it according to one of the status specified above!!!!!!

so i wud suggest u to refer back to post no. 3 from shyam...

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Richardedils
Wed Apr 24 2024, 04:07 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm
Infewow
Sun Apr 21 2024, 06:30 pm