Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Dc Motor Control Using PIC16F877 and L298: Help needed

Status
Not open for further replies.

tak_iiec@yahoo.com

Newbie level 6
Newbie level 6
Joined
Feb 28, 2011
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Visit site
Activity points
1,420
Dear All
I am making a project: Sun tracking
I am using pic16F877 and L298 and the code is in PIC Mikroc. I am stuck since many days as Motor is not running in proteus.
Kindly help how to set PWM duty cycle and how to control the speed. My complete code given below: Two LDRs are used to track the position of sun. i am giving CCP1 output to ENA pin of L298.
I dont know where the problem lies.
Plz help me out



//********************************************************************************
//POWER Window Motor Based Sun Tracker
// MCU: 16F877
// XTAL: 4MHz
// 2 LDR are used to track the position of sun
//*******************************************************************************
unsigned short current_duty;

unsigned int LDR1,LDR2;
int Error1, Error2;
void main() {
ADCON1 = 0x00;; // All analog pins AN0-AN7 are used set to analog and result id left justified.
ADCON0 = 11000111 ; // ANO
ADCON0 = 11001111 ; // AN1

TRISA = 0XFF;
TRISB = 0x00;
PORTB = 0x00;
TRISC = 0x00;
PORTC = 0x00;



CCP1CON=0b00001100; // CCP is used as PWM Mode
/*T2CON=0b00000111; // Timer2 is ON and Prescalar value is 16
PR2=255; // 0xFF : Timer prescalar value is 1, 4 or 16*/


PWM1_Init(5000);
PWM1_Start();
current_duty=25;
PWM1_Set_Duty(current_duty); // PWM Duty cycle (0-255(100%))
//*******************************************************************************
do{

start:
LDR1 = ADC_read(0); // ANO/RA0
LDR2 = ADC_read(1); // AN1/RA1

//Error = LDR1-LDR2 || LDR2-LDR1;
Error1 = LDR1-LDR2;
Error2 = LDR2-LDR1;
if((LDR1 && LDR2>=200) && (LDR1 && LDR2<=900)) {


if ((Error1 ||Error2) >=30) {
//if(LDR1<500 && LDR2>900) {
if(LDR2>LDR1) { //right brighter



PORTB.RB3 = 1;
PORTB.RB4 = 0;
Delay_ms(40);
current_duty=255;
PWM1_Set_Duty(current_duty);
Delay_ms(40);
}

//else if(LDR2<500 && LDR1>900) { // left brighter
if(LDR1>LDR2) {
PORTB.RB3 = 0;
PORTB.RB4 = 1;
Delay_ms(40);
current_duty=255;
PWM1_Set_Duty(current_duty);
}
}
else
PORTB.RB3 = 0;
PORTB.RB4 = 0;
delay_ms(2000);

}
} while(1);
}
 

Attachments

  • Doc1.doc
    135.5 KB · Views: 93

hi
i read your message
i try to make this project double axis,the mechanical constraction i completed but,i have some problem about software ccs c code, i desire from you the codes in 16f877a and isis drawing .please help me .
thank you
 

ok.i post simulation file,
exactly i want this, 2 ldr control a dc motor ,ldrs are connected to pin of pic directly ,is it correct?
in fact,i have no idea about software exactly, please help me ,this is my school project

- - - Updated - - -

To be more descriptive: 2 ldrs are control dc motor1 for example:when ld1>ld2 and ld1-ld2> any set value ,the motor1 turn to right ...else the other command
thanks :)
 

Attachments

  • WİTH LDR.rar
    21 KB · Views: 87

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top