1. samsoltats

    Thread Starter New Member

    Jul 13, 2010
    16
    0
    I doing a line following robot and i want to use sensor arranged in a inverted "V" shape for control purposes, from my sensors i am reading analog value of 1.45v when white surface is put across the sensor and 1.46 when Black surface is put across, i am struggling using ADC input for the program: The PWM alone works fine but i cannot seems to get the logic right especially using a analog input, 127 i have used as example of conversion analog input value from the sensor. may i please have help on this.

    The algorithm goes like:

    #include<16f887.h>
    #fuses RC,NOWDT,NOPROTECT,NOLVP
    #use delay(clock = 8000000, INT_OSC)
    //page 130, datasheet
    //choosing frequency = 4.90khz -> period = 204us
    //t2DIV = 4
    //timer2 prescaler, PR2 = 0x65
    //to setup the value for the pwm function:
    //Duty = duty cycle/(t2DIV(1/8000000))
    void main()
    {
    int remember = -1;
    long DutyR = 0; //50% duty cycle
    long DutyL = 0; //50% duty cycle
    set_tris_B(0xFF);
    set_tris_A(0xFF);
    set_tris_D(0x00);
    setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
    setup_ccp2(CCP_PWM); //
    setup_timer_2(T2_DIV_BY_4, 0x65, 1); //sets the frequency of the pwm?
    //delay_ms(1);
    set_pwm1_duty(DutyL);
    set_pwm2_duty(DutyR);
    while(true)
    {
    setup ADC(input_1, input_2, input_3); sensor 1,2 and 3
    do ADC(input _1)
    if (input_1< 127)
    set_pwm1_duty(DutyL);
    set_pwm2_duty(DutyR);
    turn left slightly;
    else turn right slightly

    else if (input_2<127)
    set_pwm1_duty(DutyL);
    set_pwm2_duty(DutyR);
    turn left moderately

    else turn right moderately

    else if (input_3<127)
    set_pwm1_duty(DutyL);
    set_pwm2_duty(DutyR);
    turn left sharply;
    else turn right sharply;
    }
    set_pwm1_duty(DutyL);
    set_pwm2_duty(DutyR);
    }
    thank you.
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    With a difference of only .01 volt between light and dark it would seem that your hardware is not working correctly. Can you post the schematic?

    With an 8 bit ADC and a reference of 5 volts, your lowest sensitivity is on the order of 20 mv. Until you can get more output from the sensor, the microcontroller can't "see" the line.
     
    samsoltats likes this.
  3. wannaBinventor

    Member

    Apr 8, 2010
    179
    4
    I agree that with beenthere that something is wrong with your setup/components. That small of a difference gives nothing for the uC to work from.

    What king of sensor system are you using?

    Once you get that fixed, you should set your voltage refs to just above and below tha max and min observed (through experimentation) sensor outputs as this is going to make it very easy to determine with the 8 bit ADC if it's seeing "A" or "B".
     
    samsoltats likes this.
  4. samsoltats

    Thread Starter New Member

    Jul 13, 2010
    16
    0
    I intend to amplify the output value from the sensor "HOA0708" what i am not sure about is the program and the analog value conversion in the program, could someone help me on that regard, or maybe finish off the program through the guideline that i have given on the post.

    I want to use ADC pin of the chip. thank you.
     
  5. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    Hello,

    What is the distance between the sensor and the reflective surface?
    In the datasheet is given that the optimal distance is .15 inch or 3.8 mm.

    [​IMG]

    Also how many current are you using for the IR-led?

    Bertus
     
    samsoltats likes this.
  6. samsoltats

    Thread Starter New Member

    Jul 13, 2010
    16
    0
    I used a limiting resistance of 100-ohm to have about 1.6 volts drop across the resistor, the current across the IR LED was measured as 20mA, however, after varying the Vcc up to around 8- 10V I got the current up to 50mA, which is what is required to switch on that IR LED but still it couldn't switch on. And this was done independently without including the transistor in the circuit.
    Difference source voltage was applied through the resistor Rc of about 150 ohm, the current at the collector was 20mA, tried to vary the input voltage with no success to get it to 30mA. Then at the end included the transistor into the circuit, still there was no success in getting it to switch on. i.e no voltage variation at the output, nothing, the reading that could be read there was only of voltage left after the drop at the resistor.
    That's bit of description of the experiment that I have done on that sensor and most of them have blew in the process, only one left that I think is still working. But I have ordered some again.
    Today I have configured an alternative,by using two LDR with normal LED in between them, and at least I could read something when I put the black and white paper across, but I did not do rigorous measuring on it yet. But this is the last resort if sensors wont work at all, just to get going at the moment.
    I hope this little description is understandable to you
     
  7. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
    Hello,

    Can you make a drawing of the mechanical setup?
    I want to know the distance between the sensor and the reflective surface.
    If the distance is not correct the reaction can be to less.

    [​IMG]

    Bertus
     
    samsoltats likes this.
  8. samsoltats

    Thread Starter New Member

    Jul 13, 2010
    16
    0
    K, i am still doing a prototype on the bread board, i have not yet done drawings but i am aware of the distance, however it does not work, no matter how close is put across. The connection used is the same to the one from the datasheet as simple as it is but yet it does not work as i have discussed above.
     
  9. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
Loading...