problem in implementing proximity motor control project

Questions and Comments on All Projects
rafeey
Newbie Pyro
Posts: 1
Joined: Thu May 23, 2013 5:25 pm

problem in implementing proximity motor control project

Postby rafeey » Thu May 23, 2013 5:46 pm

Hi, i am having a problem implementing your pr0ximity motor control project.the problem is that the pwn output (checked on cro)is very noisy and the duty cycle is not even the same.
i've burned the same code as on the website .plz help me with this. i am using mplab c18 to compile and chipmax programmer to burn the controller(pic18f4520).
i've also added lcd to this project to display speed. it is running well in proteus but on hardware there in very noisy output a pwn (pin 17). please help as asap because it is my semester project and i've to present it in 2 days.



my code is as follows.











#include <p18f4520.h>
#include <adc.h>
#include <delays.h>
#include <timers.h>
#include <pwm.h>

#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF

#define speed_8 1
#define speed_7 48
#define speed_6 96
#define speed_5 144
#define speed_4 192
#define speed_3 240
#define speed_2 288
#define speed_1 336
#define speed_0 1000

#define dist_6cm 634
#define dist_8cm 562
#define dist_10cm 470
#define dist_12cm 419
#define dist_14cm 368
#define dist_16cm 327
#define dist_18cm 296
#define dist_20cm 265
#define dist_22cm 245


#define RW_PIN PORTCbits.RC1 /* PORT for RW */
#define RS_PIN PORTCbits.RC3 /* PORT for RS */
#define E_PIN PORTCbits.RC0

//#define 8BIT PORTB
void print (char );
void comd(unsigned int );
void init(void);
void prntscrn(char []);


/*
*
*/
void main(void) {




char period = 0xFF;
unsigned int count = 1;
unsigned int result = 0;
char a[]="speed 8" ;
char b[]="speed 7" ;
char c[]="speed 6" ;
char d[]="speed 5" ;
char e[]="speed 4" ;
char f[]="speed 3" ;
char g[]="speed 2" ;
char h[]="speed 1" ;
//char i[]="speed 0" ;

TRISD = 0x00;


TRISCbits.RC1=0x00;
TRISCbits.RC3=0x00;
TRISCbits.RC0=0x00;
TRISB=0x00;

PORTCbits.RC1=0x00;
PORTCbits.RC3=0x00;
PORTCbits.RC0=0x00;
PORTB=0x00;
Delay10KTCYx(200);

init();
Delay10KTCYx(200);



/*
Timer2 Prescalary Details:
0b00 = Prescalar x 1
0b01 = Prescalar x 4
0b10 = Prescalar x 16
*/
T2CONbits.T2CKPS0 = 0;
T2CONbits.T2CKPS1 = 0;

// PWM Frequency = [(period ) + 1] x 4 x TOSC x TMR2 prescaler
// Tosc = 20 MHz
// TMR2 Prescalar = 1
// Period = 128
// PWM Frequency = (256) x 4 x (1/20,000,000) x 1 = 19.5 KHz
OpenPWM1( period );

//Motor Initially Off
SetDCPWM1( speed_0 );

// configure A/D convertor
OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,
ADC_CH0 & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS & ADC_INT_OFF, 0 );

Delay10TCYx( 5 ); // Delay for 50TCY
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
result = ReadADC(); // Read result

while(1){

Delay10TCYx( 5 ); // Delay for 50TCY
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
result = ReadADC(); // Read result

//Update Motor Speed Setting & LED Bar
if(result < dist_6cm && result > dist_8cm){
SetDCPWM1( speed_8 );
PORTD = 0xFF;

prntscrn(a);
}
else if(result < dist_8cm && result > dist_10cm){
SetDCPWM1( speed_7 );
PORTD = 0xFE;

prntscrn(b);
}
else if(result < dist_10cm && result > dist_12cm){
SetDCPWM1( speed_6 );
PORTD = 0xFC;

prntscrn(c);
}
else if(result < dist_12cm && result > dist_14cm){
SetDCPWM1( speed_5 );
PORTD = 0xF8;

prntscrn(d);
}
else if(result < dist_14cm && result > dist_16cm){
SetDCPWM1( speed_4 );
PORTD = 0xF0;

prntscrn(e);
}
else if(result < dist_16cm && result > dist_18cm){
SetDCPWM1( speed_3 );
PORTD = 0xE0;

prntscrn(f);
}
else if(result < dist_18cm && result > dist_20cm){
SetDCPWM1( speed_2 );
PORTD = 0xC0;

prntscrn(a);
}
else if(result < dist_20cm && result > dist_22cm){
SetDCPWM1( speed_1 );
PORTD = 0xFE;

prntscrn(g);
}
else if(result < dist_22cm){
SetDCPWM1( speed_0 );
PORTD = 0x00;

prntscrn(h);
}

Delay10KTCYx( 5 ); // Delay for 50TCY
}

CloseADC(); // Disable A/D converter
}



void init(void){
TRISB=0x00;
PORTB=0x38;
RW_PIN=0;
RS_PIN=0;
E_PIN=1;
E_PIN=0;
Delay10KTCYx(200);
PORTB=0x0F;
RW_PIN=0;
RS_PIN=0;
E_PIN=1;
E_PIN=0;
Delay10KTCYx(200);
PORTB=0x01;
RW_PIN=0;
RS_PIN=0;
E_PIN=1;
E_PIN=0;
Delay10KTCYx(200);
PORTB=0x06;
RW_PIN=0;
RS_PIN=0;
E_PIN=1;
E_PIN=0;
Delay10KTCYx(200);
}

void comd(unsigned int a){
TRISB=0x00;
PORTB=a;
RW_PIN=0;
RS_PIN=0;
E_PIN=1;
E_PIN=0;
Delay10KTCYx(200);

}
void print(char b){
TRISB=0x00;
PORTB=b;
RW_PIN=0;
RS_PIN=1;
E_PIN=1;
E_PIN=0;
Delay10KTCYx(200);

}


void prntscrn(char ar[]){

int count=0;
while(ar[count] != '\0')
{
print(ar[count]);
count++;
Delay10KTCYx(200);
}

}

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 1 guest