CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

using ADC values

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
switchblademaster
Guest







using ADC values
PostPosted: Tue Jul 28, 2009 8:39 pm     Reply with quote

ok........so I have decided to build a line following robot and getting a little trouble with using the values I get from the ADC inputs.
I have 6 inputs.......two to indicate left......two for center......and two for right

I have done my ADC conversion and I want to execute routines to tell the robot to move left or right. In the beginning of my main code I have the ADC setup.........but what do I do after???

I am thinking of using the switch statement to call different subroutines for different cases. I will be compring the sensors to a setpoint value and if any of the cases are true then it will execute the code.

Is there any other suggestions on how I can approach this problem???

This is my code:
Code:

#include <18F4520.h>
#device adc=8 //Resolution of ADC: 0-256
#device ICD=TRUE
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Oscillator; no clock out
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#use delay(clock=16M, oscillator=4M) //Clock speed of 16MHZ

#use standard_io(A1)
#define L2 PIN_A0
#define L1 PIN_A1
#define CL PIN_A2
#define CR PIN_A3
#define R1 PIN_A4
#define R2 PIN_A5

int CENTER_L;
int CENTER_R;
int LEFT_1;
int LEFT_2;
int RIGHT_1;
int RIGHT_2;
int set_point=1;
int calibrate, set_point1;
int1 i;

void main()
{

setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 255, 1); //PWM resolution 1023
setup_adc_ports(AN0_TO_AN5);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(VSS_VDD);

while(1)
{
set_adc_channel(2);
delay_us(10);
CENTER_L = read_adc();


set_adc_channel(3);
delay_us(10);
CENTER_R = read_adc();


set_adc_channel(0);
delay_us(10);
LEFT_2 = read_adc();


set_adc_channel(1);
delay_us(10);
LEFT_1 = read_adc();


set_adc_channel(4);
delay_us(10);
RIGHT_1 = read_adc();


set_adc_channel(5);
delay_us(10);
RIGHT_2 = read_adc();


if{CENTER_L>set_point}
set_pwm1_duty(CENTER_L);
set_pwm2_duty(0);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 29, 2009 1:23 pm     Reply with quote

You're asking questions about the design of a line-following robot program.
It's probably better to ask design questions in a pure Robotics forum.
Try these search strings in Google:
Quote:
line following robot CCS
or
Quote:
line following robot design
or
Quote:
line following robot forum
Guest








PostPosted: Wed Jul 29, 2009 1:33 pm     Reply with quote

No sorry..........it is not about the robot design. Probably I need to state it a little clearer. I wanted to know how can I test different situations besides using if and else if statements. I was thinking about the switch statements, but I soon realized that cannot work.

So I am testing the condition of each sensor.....and using PID control to make the robot move effectively. Getting a little trouble with the testing conditions and the PID routines. But I will work on my code and test it....sorry for the misunderstanding.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 29, 2009 2:03 pm     Reply with quote

CCS has a driver file with some routines for a line following robot:
Quote:
c:\program files\picc\drivers\line_tracker.c

They have one routine that checks the sensors. The sensor ID is passed
to the routine as a parameter (LEFT, RIGHT, or CENTER), and it selects
the appropriate A/D channel based on that. Then it reads the A/D value,
tests it, and returns a value based on whether or not it detected a
reflective surface. Maybe this can give you some ideas.
Switchblademaster
Guest







PostPosted: Wed Jul 29, 2009 2:32 pm     Reply with quote

hey thanks.........didn't even know that was there!!

that is interesting though.........I will experiment with it.

Ugh.......the big trouble now is figuring out the PID code.......anyway thanks again Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group