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.

analog PIC18f

Status
Not open for further replies.

wilsonlai3

New Member
HELO TO EVERYONE

here is my problem,
i`m having difficulty in knowing how it works

(input)IR signal -> into pic18f452 output -> L293D -> DC motor

i don know how to write the c PROGRAM
because both also analog in and output
thanks guys
 
First you need to know C and understand the concepts behind IR communication and H-Bridges.

Then break in down into steps.

1. Program the PIC to read the IR

2. Program the PIC to control the motor using the H-Bridge.

Where do you need help ?
 
guys,here are the program draft that try to simulate but it cant work.
so i not sure how to program it

the concept is like this,infront of car there will be a IR sensor which detect distance infront of car,if distance is decrease the speed of motor will decrease also,and vise verse.

here are part of the program.

unsigned int temp_res;

void main() {
ADCON1 = 0x80; // Configure analog inputs and Vref
TRISA = 0xFF; // PORTA is input
TRISB = 0x3F; // Pins RB7, RB6 are outputs
TRISD = 0; // PORTD is output
T2CON = 0b00011110; //set up PWM
CCP1CON = 0b00001100;
CCP2CON = 0b00001100;
CCPR1L = CCPR2L = 0; //initial PWM is zero
do {
temp_res = Adc_Read(2); // Get results of AD conversion
PORTD = temp_res; // Send lower 8 bits to PORTD
PORTB = temp_res >> 2; // Send 2 most significant bits to RB7, RB6
} while(1);
}
 
It is much easier to read code if you post it using the # icon from the menu. It place the code between
Code:
tags.
Code:
unsigned int temp_res;

void main() {
   ADCON1 = 0x80; // Configure analog inputs and Vref
   TRISA = 0xFF; // PORTA is input
   TRISB = 0x3F; // Pin
You are making me guess at what compiler you are using.

I see a adc read but no call to set it up. It is very hard to debug a parts missing turkey ! :)

3v0
 
i`m using MIKROC
to compile it

so the problem is as what u stated
i don noe how to call it and cooperate with PWM output
 
I looked at the compiler manual as did you. My question is why are you using the supplied ADC functions and not the supplied PWM functions. My guess is that they would work well together.

The PWM functions are
Pwm_Init
Pwm_Change_Duty_Cycle
Pwm_Start
Pwm_Stop​
Code:

This is the way you can combine the two examples from the compiler manual. You still need to figure out what value to set the PWM duty to based on the ADC reading. I did not provide header files or fuse settings. These you should be able to figure out.


Code:
void main(void)
{
  // setup ADC
  ADCON1 = 0x80; // Configure analog inputs and Vref
  TRISA = 0xFF; // PORTA is input
  TRISB = 0x3F; // Pins RB7, RB6 are outputs
  TRISD = 0; // PORTD is output

  // setput PWM  
  TRISC=0x00;
  PORTC=0xFF;
  Pwm_Init(???);
  Pwm_Start();

  while(1)
  {
      // code to read ADC
      .....
      // code to set PWM duty cycle 
      ....
      Pwm_Change_Duty(???);
  }
}

I do not use this compiler but it looks lke this should work.
 
programing

First you need to know C and understand the concepts behind IR communication and H-Bridges.

Then break in down into steps.

1. Program the PIC to read the IR

2. Program the PIC to control the motor using the H-Bridge.

Where do you need help ?

could u please write a little bit programing to program the pic to control the dc motor..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top