Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Wireless control.........

Status
Not open for further replies.
Did you learn anything?
 
Yes..
if 100 is 1024 so, 1 equal to 10.24..
please how to get all values between 1 to 100 conversion in ADC.

What? Is this a whole new topic?
 
Last edited:
Hi,

Actually i am building wireless robot with speed control so, LCD on remote will tell the Total % speed of robot.

How do you get the speed of the robot using ADC? What kind of speed sensor you have?
 
How is it connected? How does it work? What is eject?

I will do it never mind.....the speed controller potentiometer will control speed and simultaneous the LCD will show the % of total/maximum speed of it can achieve..
 
I will do it never mind.....the speed controller potentiometer will control speed and simultaneous the LCD will show the % of total/maximum speed of it can achieve..

I am a mechatronics guy and I would be very interested to know how you are getting speed information using potentiometer?
 
Stardate 2257.901

That new enginear is now a weapon designed to confuse the enemy...........
 
Hi,

It is not working after HserinString(inbuff); // get incomming data is there any problem in code...?

Rx
Code:
#include <htc.h>
#include <stdlib.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
 
unsigned char inbuff[12];					// Transmision buffer
void  HSerinit(void), HserinString(unsigned char*);
unsigned char Hserin(void);					// transmission functions
int getInt(unsigned char* str);			// a sort of atoi
 
void main(void)
	{
int rxdata;				// incomming data store
	PR2 = 0b11111001 ;
	T2CON = 0b00000100 ;   
	CCP1CON = 0b00111100;                  
	ADCON1 = 0x6;                 
	HSerinit();  

TRISD=0X00;
unsigned char ch; 
RD0=0;
RD1=0;
RD2=0;
RD3=0; 
	while(1)
		{
RD0=1;       // for testing hardware it is working till here..
RD1=0;
RD2=1;
RD3=0; 
__delay_ms(502);
RD0=0;
RD1=1;
RD2=0;
RD3=1; 
__delay_ms(502);
RD0=0;
RD1=0;
RD2=0;
RD3=0;
HserinString(inbuff);		// get incomming data
		rxdata = getInt(inbuff);	// turn to decimal
   		CCPR1L = (unsigned char)rxdata ;// set PWM


ch=Hserin();
if(ch=='a'){
RD0=1;
RD1=0;
__delay_ms(2);
}
if(ch=='b'){
RD0=0;
RD1=1;
__delay_ms(2);
}
if(ch=='c'){
RD2=1;
RD3=0;
__delay_ms(2);
}
if(ch=='d'){
RD2=0;
RD3=1;
__delay_ms(2);
}
if(ch=='e'){
RD1=1;
RD3=1;
__delay_ms(2);
}
if(ch=='f'){
RD0=1;
RD2=1;
__delay_ms(2);
}
ch=0;
RD0=0;
RD1=0;
RD2=0;
RD3=0; 
		}
	}

		
	
 
void HserinString(unsigned char* str)
	{
	int i = 0;
	while(str[i++] != 0x0D)	// wait for carriage return
		str[i] = Hserin();	// get next character
 
	}
 
int getInt(unsigned char* str) // sort of atoi
	{
	int result = 0;
	while(*str !=0x0D)		// until we see carriage return
		{
		if(*str >0x29 && *str < 0x3A)	// Is it a number
			{
			result*=10;
			result+= *str - 0x30;		// convert to int
			}
		str++;
		}
	return result;		// all done
	}
 
unsigned char Hserin(void)
	{
	while(!RCIF);
	return RCREG;	
	}
 
void HSerinit(void)
	{
    TRISC = 0x80;                    // TX was an input!
    SPBRG = 129;                    // 20Mhz xtal 9600 BAUD
    TXSTA = 0x24;                    // TXEN and BRGH
    RCSTA = 0x90;                    // SPEN and CREN
	}



Tx
Code:
#include <htc.h>
#include	<stdio.h>
#include <stdlib.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
#define N 10
#define M 1	
#define DATA PORTB
#define EN RC4
#define RS RC5

 void LCDcmd(char x), LCDdata(char x);

void LCD_goto(char line, char column)	;
unsigned char outbuff[12];
void  HSerinit(void), HseroutString(unsigned char* str), Hserout(unsigned char ch);
void LCD_printR(char *str);
 unsigned char m[11]="  ROBO'91";
 unsigned char z[17]="The Ultm Robotix";
unsigned char x[6]="Speed";
unsigned long number=0;		// Number MUST be a long for fixed point
int ch=0;
unsigned char LCDbuffer[17];

void main(void)                        
    { 

	TRISB=0X00;  
	TRISC=0X00;                 
    TRISD=0b00001111;   
	__delay_ms(150);
 	LCDcmd(0x38); // init
	__delay_ms(N);
	LCDcmd(0x38); // init
	__delay_ms(N);
	LCDcmd(0x38); // Function set
	__delay_ms(N);
 	LCDcmd(0x06); // Cursor move increase, no display shift
	__delay_ms(N);
	LCDcmd(0x0C); // Display on, cursor off, not blinking
 
	__delay_ms(N);
	LCDcmd(0x01); // Clear display. goto pos 1
 	__delay_ms(N);
unsigned char ch;


	__delay_ms(150);
	LCD_goto(1,2);
		LCD_printR(m);
	LCD_goto(2,0);
		LCD_printR(z);
	__delay_ms(3000);
	LCDcmd(0x01); // Clear display. goto pos 1
	int txdata;		// data to transmit
	TRISA = 0xff ;                             
    HSerinit();
	__delay_ms(100);
TRISA = 0xff ;
	ADCON1=0b10000000;		// Left justified
	ADCON0=0b01000001;//000 = channel 0, (RA0/AN0)
	ADIF=0;
	ADIE=1;
	PEIE=1;
    while(1)                
        {

	LCD_goto(1,4);
		LCD_printR(m);


 
		LCD_goto(2,0);
	LCD_printR(x);
		LCD_goto(2,6);

		number = ReadADC();
 
		number = number * 100 / 1024;
		LCDbuffer[0]= (number / 1000)+ 48;
		LCDbuffer[1] = 46;
		LCDbuffer[2] = ((number % 1000) / 100)+ 48;
		LCDbuffer[3] = ((number % 100) / 10)+ 48;
		LCDbuffer[4] = (number % 10) + 48;
		LCDbuffer[5] = 0;
		LCD_printR(LCDbuffer);
 		number = number *5000 / 1023;
		sprintf(LCDbuffer," %02d%%",number);
txdata = ReadADC();				// get analogue value on RA0
		sprintf(outbuff,"%d\r",txdata);	// convert to ascii text
		HseroutString(outbuff);			// send data

if((RD0==1)&&(RD1==0)&&(RD2==0)&&(RD3==0)){
ch='a';
 Hserout( ch);
__delay_ms(2);
}
if((RD0==0)&&(RD1==1)&&(RD2==0)&&(RD3==0)){
ch='b';
 Hserout( ch);
__delay_ms(2);
}
if((RD0==0)&&(RD1==0)&&(RD2==1)&&(RD3==0)){
ch='c';
 Hserout( ch);
__delay_ms(2);
}
if((RD0==0)&&(RD1==0)&&(RD2==0)&&(RD3==1)){
ch='d';
 Hserout( ch);
__delay_ms(2);
}
if((RD0==0)&&(RD1==1)&&(RD2==0)&&(RD3==1)){
ch='e';
 Hserout( ch);
__delay_ms(2);
}
if((RD0==1)&&(RD1==0)&&(RD2==1)&&(RD3==0)){
ch='f';
 Hserout( ch);
__delay_ms(2);
}
ch=0;
__delay_ms(5);
	}
 

 }

 

 


void LCDcmd(char x)
	{
	__delay_ms(N);
	RS=0;

	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA = x;	// Command data
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
	}
void LCDdata(char x)
	{
	RS=1;

	__delay_ms(M);
	EN=1;
	__delay_ms(M);
	DATA = x;  //  Print data
	__delay_ms(M);
	EN=0;
	__delay_ms(M);
	}
 
void LCD_goto(char line, char column)		// combines line and lineW
	{
	unsigned char data = 0x80;				// default to 1
	if(line == 2)data = 0xc0;				// change to 2
	data += column;							// add in  column
	 LCDcmd(data);
	}

void LCD_printR(char * str)	 		// This passes the start of a RAM character array
	{								// by default the pointer points to data section
	while(*str != 0)				// while the character pointed to isn't 0
		LCDdata(*str++);			// print out the character, then increment
	}

void HSerinit()
	{
    TRISC = 0x80;                    // TX was an input!
    SPBRG = 129;                    // 20Mhz xtal 9600 BAUD
    TXSTA = 0x24;                    // TXEN and BRGH
    RCSTA = 0x90;                    // SPEN and CREN
	}

 
int ReadADC()
	{
	int ret = 0;
	__delay_ms(10);
	GO_DONE = 1;					// start conversion
   	while(GO_DONE);					// wait for conversion
   	ret =  (ADRESH & 0x3) << 8;		// get
   	ret +=	ADRESL;					// result
	return ret;
	}

void HseroutString(unsigned char* str)
	{
	while(*str != 0)			// while all transmitted
		Hserout(*str++);	
	}
 
void Hserout(unsigned char ch)
	{
	while(!TXIF);
	TXREG = ch;	
	}
 
I have connected LED at RD0-RD3 all are working when switch is pressed from Tx..the LEd blink but the motor does not rotates, L293 is working because at starting of code it moves as per code...after pressing button on remote led glow but motor does not work..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top