1. 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.
    Dismiss Notice

PIC16f690, initialisation of ports, LEDS,reading from a pin

Discussion in 'Microcontrollers' started by fantabulous68, Aug 24, 2009.

  1. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,791
    Likes:
    134
    Location:
    morristown,tn
    ONLINE
    A pic 16f690 can do 16 bit math the compiler handles it for you
    How long do you you have to get this to work fanta?
    The 18f1320 is 8 bit to lol
    16 bit chips are pic24f pic24h dspic30 dspic33
    and the pic32 it's 32 bit
     
    Last edited: Aug 29, 2009
  2. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0
    lol OK,:eek:, uhmmmm im new with the programming guys-sorry for asking alot of silly questions...just want to make sure i do it right this time. I have like a month and 1week left be80be.
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,174
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    I would recommend that you try the Sharp GP2 opto to check that it will work from the water surface over the range you require.

    A clear water surface is a very poor reflector for IR or visible light, just look into a bowl of water and you see how little it reflects at 90deg.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0

    Yeah i will do that when the GP2 arrives, Im not constrained to using water. I just have to test which liquids it works best with, and add those to my final specifications and use those to demonstrate with.
     
  6. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0
    Programming the Sharp GP2 sensor PIC16f690

    This is for the PIC 18F1320 BUT i want to modify this code to suit the PIC16f690. I am trying but not sure about a few things. I attached a word document with the relevent datasheets from the 18F and 16F.

    Code (text):
    void main()
    {
        // setup the [B]PIC 18F1320[/B]
        OSCCON = 0x72;          // internal osc, 8MHz

        PORTA = 0;
        [COLOR="Red"]TRISA = 0b10000010;[/COLOR]    // RA7 high imp, RA3 is serial out,
                                // RA1 is ADC input measuring VR1
        PORTB = 0;
        INTCON2 = 0;            // PORTB pullups ON
        TRISB = 0b00000000;     // PORTB not used

    [COLOR="Indigo"]    ADCON0 = 0b00000101;    // ADC ON, RA1 is ADC input
        ADCON1 = 0b01111101;    // AN1 is ADC input
        ADCON2 = 0b10100010;    // right justify, [B][I]8Tad[/I][/B], 32Tosc[/COLOR]

        T1CON = 0b00010001;     // TMR1 is ON, 1:2 prescale, =1MHz

        T3CON = 0b00010001;     // TMR3 is ON, 1:2 prescale, =1MHz

        // main loop here;
        while(1)
        {
            // wait for 2 seconds, uses TMR1 free running at 1Mhz
            while(!PIR1.TMR1IF);    // wait for TMR1 overflow
            PIR1.TMR1IF = 0;        // clear overflow flag
            LATA = 0;               // all LEDs off
           
            bres += 65536;          // add 65536uS to bres value
            if(bres >= 2000000)     // if reached 2 seconds!
            {
                bres -= 2000000;    // subtract 2 seconds, keep error
           
                // flash Junebug LED1,  RA0=1 RA6=0 RA7=hiimpedance
                LATA.F0 = 1;            // LED on

                // read the ADC voltage RA1 (Sharp GP2 sensor)
                ADCON0.F1 = 1;      // set GO bit, start doing ADC
                while(ADCON0.F1);   // wait until ADC done
                calc_distance();        // convert ADC value to distance
                send_serial_message();  // send message back to PC!
            }

        }
    }
    My code to suit pic 16f690:

    Code (text):
        [COLOR="Red"]TRISA = 0b10000010;[/COLOR]    // RA7 high imp, RA3 is serial out,
                    // RA1 is ADC input measuring VR1
    Question1:The 16f690 doesnt have a RA7. What does makin the pin a high impedance mean? Im assuming imp is impedance. I know TRIS sets pins as inputs and outputs.

    *********************************************************
    Im sure this part is right:)Easy part
    //18F
    Code (text):
    PORTB = 0;
    INTCON2 = 0;            // PORTB pullups ON
    TRISB = 0b00000000;     // PORTB not used
    //16F
    Code (text):
    PORTB = 0;          
    WPUB = 1;
    RABPU = 0;

    *********************************************************

    //18F
    Code (text):

    [COLOR="Indigo"]ADCON0 = 0b00000101;    // ADC ON, RA1 is ADC input
    ADCON1 = 0b01111101;    // AN1 is ADC input
    ADCON2 = 0b10100010;    // right justify, 8Tad, 32Tosc[/COLOR]

    //16F

    Code (text):
    ADCON0 = 0b10000101;    // bit 7 right justify,analogue channel select bits bits5-2  0001=AN1,ADC ON, RA1 is ADC input
    ADCON1 = 0b00100000;    //bits6-4  fosc/32
     
    Question2:
    I dont know how to set 8Tad on the 16f690. Could someone please tell me how to do that?

    Question3:
    Does analogue channel select bits bits5-2 0001=AN1 mean that AN1 is ADC input?


    Im going to collect the sharp GP2 today
     

    Attached Files:

    Last edited: Sep 1, 2009
  7. fantabulous68

    fantabulous68 Member

    Joined:
    Feb 20, 2007
    Messages:
    323
    Likes:
    0
    Any comments on the quote below? I already stopped with my TOF approach to this design.

     

Share This Page