please need help in two axes solar tracker using pic16f877a

Thread Starter

choura

Joined Aug 15, 2012
7
hi friends .

can any one help me with this project because i don't have enough experiences with pic; my project is about: " solar tracker with two axes using pic microcontroller pic16f877a" also i going to use DC motor 12V and PWM to control speeding of motors

this my trying circuit (in attachment files)"capture 1 image"; if there are errors or something missing please tell me

and the other circuit for driving DC motor ; please correct me how to build it correctly "capture 2 image" or the first driving DC motor is correct in the first image


and this is my program I have tried before please please I really need help with this project; correct me in this mikroC pro for pic program

/motor
#define m_R1 PORTB.F2 //pin35
#define m_R2 PORTB.F3 //pin36
#define m_L1 PORTB.F4 //pin37
#define m_L2 PORTB.F5 //pin38
//speed control for motor
#define PWM_1 CCPR2L //pin16
#define PWM_2 CCPR1L //pin17
unsigned int LDR1,LDR2,LDR3,LDR4;
void forward_MOTOR1(unsigned char R)
{
m_R1 = 0;
m_R2 = 1;
PWM_1 = R;
delay_ms(1000);
m_R1 = 0;
m_R2 = 0;
}
void backward_MOTOR1(unsigned char R)
{
m_R1 = 1;
m_R2 = 0;
PWM_1 = R;
delay_ms(1000);
m_R1 = 0;
m_R2 = 0;
}
void forward_MOTOR2(unsigned char L)
{
m_L1 = 0;
m_L2 = 1;
PWM_2 = L;
delay_ms(1000);
m_L1 = 0;
m_L2 = 0;
}
void backward_MOTOR2(unsigned char L)
{

m_L1 = 1;
m_L2 = 0;
PWM_2 = L;
delay_ms(1000);
m_L1 = 0;
m_L2 = 0;
}
void main() {
ADCON1 = 0x00;;
TRISA = 0XFF;
TRISB = 0x00;
PORTB = 0x00;
TRISC = 0x00;
PORTC = 0xFF;
TRISD = 0x00;
PORTD = 0x00;
CCP1CON=CCP2CON=0b00001100;
T2CON=0b00000111;
PR2=255;
PWM_1=PWM_2=0;
while(1){
LDR1 = ADC_read(0);
LDR2 = ADC_read(1);
LDR3 = ADC_read(2);
LDR4 = ADC_read(3);
if (LDR1>900 && LDR2<560) { //right brighter
PORTD.F0 = 1;
PORTD.F1 = 0;
PORTD.F2 = 0;
PORTD.F3 = 0;
PORTB.F4 = 0;
PORTB.F5 = 1;
CCPR1L = 50;
delay_ms(500);
PORTB.F4 = 0;
PORTB.F5 = 0;
CCPR1L = 0;
delay_ms(500);}
else if (LDR1<900 && LDR2>560){ // left brighter
PORTD.F0 = 0;
PORTD.F1 = 1;
PORTD.F2 = 0;
PORTD.F3 = 0;

PORTB.F4 = 1;
PORTB.F5 = 0;
CCPR1L = 50;
delay_ms(500);
PORTB.F4 = 0;
PORTB.F5 = 0;
CCPR1L = 0;
delay_ms(500);}
else if (LDR3<500 && LDR4>800){ //up brighter
PORTD.F0 = 0;
PORTD.F1 = 0;
PORTD.F2 = 0;
PORTD.F3 = 1;
PORTB.F2 = 1;
PORTB.F3 = 0;
CCPR2L = 50;
delay_ms(500);
PORTB.F2 = 0;
PORTB.F3 = 0;
CCPR2L = 0;
delay_ms(500);}
else if (LDR3>500 && LDR4<800){ // down brighter
PORTD.F0 = 0;
PORTD.F1 = 0;
PORTD.F2 = 1;
PORTD.F3 = 0;
PORTB.F2 = 0;
PORTB.F3 = 1;
CCPR2L = 50;
delay_ms(500);
PORTB.F2 = 0;
PORTB.F3 = 0;
CCPR2L = 0;
delay_ms(500);}
else if ((LDR3<550 && LDR4<800) || (LDR1<900 && LDR2<560)){
PORTD.F0 = 1;
PORTD.F1 = 1;
PORTD.F2 = 1;
PORTD.F3 = 1;
delay_ms(100);
PORTD.F0 = 0;
PORTD.F1 = 0;
PORTD.F2 = 0;

PORTD.F3 = 0;
PORTB.F2 = 0;
PORTB.F3 = 0;
CCPR2L = 0;
delay_ms(500);
PORTB.F4 = 0;
PORTB.F5 = 0;
CCPR1L = 0;
delay_ms(500);
PORTB.F4 = 0;
PORTB.F5 = 0;
CCPR1L = 0;
delay_ms(500);}
/*else if (LDR1<900 && LDR2<560){
PORTD.F0 = 1;
PORTD.F1 = 1;
delay_ms(100);
PORTD.F0 = 0;
PORTD.F1 = 0;
PORTB.F4 = 0;
PORTB.F5 = 0;
CCPR1L = 0;
delay_ms(500);} */
}
}
 

Attachments

Top