the ultrasonic SRF04 with pic16f88


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Mar 2008
    Location
    london
    Posts
    15

    Default the ultrasonic SRF04 with pic16f88

    hello everybody

    I have few problems with my ultrasonic ranger the SRF04.
    I managed to make it work with a pic 16f84 to measure distances in inches and centimeters and display the results on a serial lcd. worked really fine.

    then i tried to use the pic 16f88 with an internal clock ; but the lcd displays 0cm and 0 inches all the time which means that the SRF04 is not doing the job (the internal clock is working by the way. i tested it with another code)

    here is a part of my code in picbasic pro:

    DEFINE OSC 4
    INTRC_OSC_NOCLKOUT
    INTRC_IO
    OSCCON=%01101000

    include "modedefs.bas"



    trisa = %11111111
    trisb = %00000000

    lcd var portb.7
    'piezo var portb.4
    trigger var portb.6
    echo var porta.0

    baud con N2400
    dist_raw var word
    dist_inch var word
    dist_cm var word
    conv_inch con 15
    conv_cm con 6

    low trigger


    serout lcd,baud,[254,1] 'clear lcd screen
    pause 1000

    serout lcd,baud,[254,128,"-sonar ranger-"]

    'sound piezo,[100,10,50,5,70,10,50,2] 'make startup sound
    pause 1000 'pause 1 sec

    serout lcd,baud,[254,128,"inches: "] 'set up the lcd display
    serout lcd,baud,[254,192,"centimeters: "]

    main:

    gosub sr_sonar

    serout lcd,baud,[254,135,#dist_inch," "] 'display the disance in inches

    serout lcd,baud,[254,204,#dist_cm," "] 'display the distance in cm

    goto main

    end

    sr_sonar:

    pulsout trigger,1 'send a 10us trigger pulse

    pulsin echo,1,dist_raw 'start timing the pulse width
    'on echo pin
    dist_inch = (dist_raw/conv_inch)
    dist_cm = (dist_raw/conv_cm)

    pause 1

    return



    i suppose that the pins of the pic are not inputing or outputing the right datas. may be because i did not set the input and output properly.
    i had been strogling for few days , please help me to make it work.
    thanx
    regards
    Last edited by tur_bot; - 16th March 2008 at 18:58.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    Just an idea ...

    May be some comparators and adc to disable ???

    Good evening

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Mar 2008
    Location
    london
    Posts
    15


    Did you find this post helpful? Yes | No

    Red face how ??

    good idea but how can I do it???
    how can I disable the ADC and comparators in a 16f88???

  4. #4
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    There could be a possibility to find that kind of information in the datasheet.

    I did that for all types I use and it worked !!

  5. #5
    Join Date
    Mar 2008
    Location
    london
    Posts
    15


    Did you find this post helpful? Yes | No

    Default datasheet

    hi
    i just tested my port with few led and they work fine, inputing and outputting.
    but the srf04 is still not working.
    I have no idea of what is going on.

    anybody with an idea????

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    - Try External clock !!! ( internal Osc is "not so accurate" ...)

    - Place "Low trigger" just before "Pulsout"

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Mar 2008
    Location
    london
    Posts
    15


    Did you find this post helpful? Yes | No

    Unhappy still not working

    i just tryied to use the external clock again.
    but it is still not working.

    any one with an idea, please ??????

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tur_bot View Post
    i just tryied to use the external clock again.
    but it is still not working.
    any one with an idea, please ??????
    Re-read post #2 and post #4...
    Look at your program...
    Take a good look at PortA.0
    Compare PortA.0's function from the datasheet to what you are trying to do with it...

    Get back to us with the results...

  9. #9
    Join Date
    Mar 2008
    Location
    london
    Posts
    15


    Did you find this post helpful? Yes | No

    Default what do you mean

    what do you mean by check porta.0 , read post2 and 4 ????? do you mean that the porta.0 is analog and I shouldn't use it for digital signals input????

    anyway , I moved the echo signal to differents port.b's and port.a's and nothing changed.

    I tested few portB input pins with infrared detectors ( which worked fine) but when the echo input signal, is connected to the same portb that i just tested , and the trigger signal output (connected to portb output pins that i tested with LEDs) of my srf04 are connected , nothing is working

    can you tell me clearly what do you have in mind please???

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tur_bot View Post
    can you tell me clearly what do you have in mind please???
    Nope...I don't have your circuit running with your software running on your hardware programmed by your programmer.
    There are numerous differences between the 16F84 and the 'F88. I'm not going to spell them all out because they're already in the datasheets.

  12. #12
    Join Date
    Mar 2008
    Location
    london
    Posts
    15


    Did you find this post helpful? Yes | No

    Talking thank you so much

    thank you so much. you are a star
    finally everything is working with internal clock and measurements well displayed on the lcd.

    wasn't that easy to understand the data sheet but because of all of you guys, with all your examples and suggestions , i managed to find the right settings.

    again thank you guys
    God bless you all

  13. #13
    Muaz's Avatar
    Muaz Guest


    Did you find this post helpful? Yes | No

    Default

    Hi, This post of mine is very knowledgable and may enhance the information of the viewers , however I would like some specific information for myself. If someone can help me then please send me a private message. Best Regards,

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tur_bot View Post
    wasn't that easy to understand the data sheet but because of all of you guys, with all your examples and suggestions , i managed to find the right settings.
    Just curious...which bit fixed the problem?
    Invariably, it's usually that one little bit that fixes everything...

  15. #15
    Join Date
    Mar 2008
    Location
    london
    Posts
    15


    Did you find this post helpful? Yes | No

    Default which bit fixed the problem

    Quote Originally Posted by skimask View Post
    Just curious...which bit fixed the problem?
    Invariably, it's usually that one little bit that fixes everything...
    those 6 lines allowed me to use an accurate inside clock and to use all pins as digital input or outputs:

    DEFINE OSC 4
    INTRC_OSC_NOCLKOUT
    INTRC_IO
    OSCCON=%01101000
    ANSEL=%00000000 'this comand disable all adc
    CMCON=%00000111 'this bit disable all comparators


    the two last commands fixed the problem to get just digital inpout and outpout on all 15 pins available, and disabled all adc and comparators.

  16. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tur_bot View Post
    the two last commands fixed the problem to get just digital inpout and outpout on all 15 pins available, and disabled all adc and comparators.
    Just like posts #2, #4, #8, #10 said it would...

Similar Threads

  1. RX TX modules - intermitent communication
    By ruijc in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 11th June 2009, 00:13
  2. Replies: 8
    Last Post: - 7th December 2006, 15:42
  3. PIC16F88 problem with TOGGLE command?
    By russman613 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th September 2006, 23:31
  4. sensor ultrasonic 8051&PIC
    By hd_uni_pro in forum Schematics
    Replies: 1
    Last Post: - 13th September 2006, 12:58
  5. SRF04 Range Finder 16F628 R18iXL Board
    By Spindle in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 02:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts