How to generate 40MHz pulse with PWM command for my ultrasonic transmitter..please


Closed Thread
Results 1 to 24 of 24
  1. #1
    Join Date
    Sep 2008
    Posts
    3

    Default How to generate 40MHz pulse with PWM command for my ultrasonic transmitter..please

    cORRECTION....i want to use command PWM to generate 40KHz (NOT 40mHZ) pulse for my ultrasonic transmitter but i cannot find the way..I use Port E for the ultrasonic transmitter..I hope anyone can help me with code examples ... maybe suggest another way to generate that pulse... Thank you..
    Last edited by chenko; - 21st September 2008 at 07:55. Reason: MISTAKE

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chenko View Post
    i want to use command PWM to generate 40MHz pulse for my ultrasonic transmitter bit i cannot find the way..I use Port E for the ultrasonic transmitter..I hope anyone can help me with code examples that may help me... maybe suggest another way to generate that pulse... Thank you..
    40Mhz eh?
    Probably 40Khz...
    What have you tried so far? Can you blink an LED? If you can blink an LED, all you have to do is make it blink at 40khz and you're set.
    What kind of hardware do you have?
    What kind of software are you using?
    What kind of programming have you done?
    You don't give a lot of information to work with ya know.
    There's a bunch of different ways to generate a 40khz pulse stream...Not a lot of ways to generate a 40Mhz pulse stream using a PIC.

  3. #3
    Join Date
    Sep 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default more info

    I used PIC 16F877A in my project..My project is Smart System of Ultrasonic Car parking...The purpose of the project is try to detect the distance between car and obstacle then display the range on the LCD..I used PIC Basic Pro for the coding..I want to generate 40Khz (not 40Mhz like I state before) because that is my frequency of ultrasonic transmitter
    Last edited by chenko; - 21st September 2008 at 07:57. Reason: correction

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chenko View Post
    I used PIC 16F877A in my project..My project is Smart System of Ultrasonic Car parking...The purpose of the project is try to detect the distance between car and obstacle then display the range on the LCD..I used PIC Basic Pro for the coding..I want to generate 40Mhz because that is my frequency of ultrasonic transmitter
    Are you sure about that 40Mhz?
    Are you sure 40Mhz falls in the range of an ultrasonic transmitter?

  5. #5
    Join Date
    Sep 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default my mistake..

    yup..you're correct...only 40kHz..i was mistaken by look to the other datasheet..thank you.. can you help me with the coding to generate that 40kHz..??

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


    Did you find this post helpful? Yes | No

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Let the weeding begin...
    It will be great when Bruce finishes his book. I will be doing some weeding then too
    Dave
    Always wear safety glasses while programming.

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    It will be great when Bruce finishes his book. I will be doing some weeding then too
    $20 says that even when Bruce does finish the book, we'll still be answering the same questions over and over and over...and not because of a lack of information from the book.
    Maybe Bruce can include a couple of hands with each book.. ya know, for the user to hold while messing around with the PICs.

  10. #10
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default My tests

    I am working with the following code using the lcd to display distance with the Ping sensor.
    I am using the QL200 development board, so my DEFINE statements may be different or un-needed for you. My problem is that the ping sensor works,( I can see it on my oscilloscope),
    but I cannot get a reading on my lcd. Only 0.
    Any help would be appreciated!.

    ' File......sonar1.pbp
    ' Microcontroller used: Microchip Technology 16F887
    '--------Program Desciption--------
    ' Using the ping ultrasonic range finder,
    ' the distance from the range finder to an object
    ' is displayed on an LCD screen in inches.
    ' rb0 is signal in/out
    define osc 4
    adcon1 = %00000000
    define lcd_dreg portd
    define lcd_dbit 4
    define lcd_ereg porta
    define lcd_ebit 3
    dist var byte
    range var word
    inches CON 15 'Assigns the value 15 conversion
    pause 2000

    sonar 'Pulse Width
    pulsout 0,20
    pauseus 100
    pulsin 0,10,range
    dist = range/inches 'Converts raw sonar reading to inches
    LCDOUT $FE,1,"Distance"
    LCDOUT $FE,$14,#range
    PAUSE 2000
    GOTO sonar
    END

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default

    Try the DEIFINE's in capital.

    Ioannis

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    The define, in this case, won't make any difference since it's define osc 4, which is PBP default...

    Code:
    sonar   'Pulse Width
    How does that work? Is it a label? Is it a command? Is it a comment?

    Code:
    pulsout 0,20
    pauseus 100
    pulsin 0,10,range
    You wait for 100us instead of going straight to looking for a return pulse? How does THAT work? Shouldn't you jump directly to looking for the return pulse?
    Which version of PBP are you using?

  13. #13
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Tried capitalizing Define's but to no avail, you're right though they are supposed to be in capitol. Any other ideas??
    Last edited by Picstar; - 22nd September 2008 at 14:25.

  14. #14
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    You're right missing : in sonar label. According to the specs on the ping unit, there is a 750us pause called a "holdoff?". At any rate, I have tried it without a pause and have changed timing in the pulsin and pulsout commands, but still no luck. Using PBP 2.50b. heres the latest code:


    ' File......sonar1.pbp
    ' Microcontroller used: Microchip Technology 16F887
    '--------Program Desciption--------
    ' Using the ping ultrasonic range finder,
    ' the distance from the range finder to an object
    ' is displayed on an LCD screen in inches.
    ' rb0 is signal in/out
    adcon1 = %00000000
    define LCD_DREG PORTD
    define LCD_DBIT 4
    define LCD_EREG PORTA
    define LCD_EBIT 3
    dist var byte
    range var byte
    inches CON 15 'Assigns the value 15 conversion
    pause 2000

    sonar: 'Pulse Width
    pulsout portb.0,20
    pulsin portb.0,100,range
    'dist = range/inches 'Converts raw sonar reading to inches
    LCDOUT $FE,1,"Distance"
    LCDOUT $FE,$14,#range
    PAUSE 2000
    GOTO sonar
    END
    Last edited by Picstar; - 22nd September 2008 at 14:28.

  15. #15
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Re-read the manual on the use of the pulsin statement.

    You say the unit has a 'holdoff' of 750us, and yet you originally used a pauseus of 100. What's up with that?

  16. #16
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Pulsin pin,state,var. State can only be a 1 or 0.

    Also you need to disable A/D. Several pins you're using have A/D enabled by default.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  17. #17
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

  18. #18
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Default some success!

    Thanks to you all for your responses. The following code works but only after I hit the reset
    button on my dev. board, then it works all the time. Even after shutting off power and restarting...strange. I'm a newbie so I'm puzzled by all the cmcon, adcon1, trisb etc. Read the datasheet on my pic? Yeah, right looks like Chinese to me.

    ' File......sonar1.pbp
    ' Microcontroller used: Microchip Technology 16F887
    '--------Program Desciption--------
    ' Using the ping ultrasonic range finder,
    ' the distance from the range finder to an object
    ' is displayed on an LCD screen in inches.
    ' rb0 is signal in/out
    anselh = 0
    define LCD_DREG PORTD
    define LCD_DBIT 4
    define LCD_EREG PORTA
    define LCD_EBIT 3
    dist var word
    range var word
    inches CON 13 'Assigns the value 13 conversion
    pause 2000 'wait for lcd to initialize
    sonar:
    pulsout portb.0,20
    pulsin portb.0,1,range
    dist = (range/inches) 'Converts raw sonar reading to inches
    LCDOUT $FE,1,"Distance"
    LCDOUT $FE,$14,#dist
    PAUSE 2000
    GOTO sonar
    END

  19. #19
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    See if this helps. Add this to the init section of your code;

    ANSEL = 0 ' disable A/D on porta
    LOW 0 ' make portb.0 low so pulsout = a high going pulse on RB0

    PULSOUT toggles a pin so the initial state of the pin should be set to the opposite of the
    pulse logic you want.

    ANSEL = 0 disables A/D for porta & porte.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  20. #20
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Smile Ok

    Well, getting back to Chenko's original question, here is my latest code that includes an alarm when an object is closer than a preset limit. Thank's Bruce, but still no luck with reset problem. However, the code DOES work! Chenko you may need to change portb.0 to porte.0 and set the define statements for your board.

    ' File......sonar1.pbp
    ' Microcontroller used: Microchip Technology 16F887
    '--------Program Desciption--------
    ' Using the ping ultrasonic range finder,
    ' the distance from the range finder to an object
    ' is displayed on an LCD screen in inches.
    ' rb0 is signal in/out
    ' alarm is sent when object is too close.
    ' reset before use
    anselh = 0
    define LCD_DREG PORTD
    define LCD_DBIT 4
    define LCD_EREG PORTA
    define LCD_EBIT 3
    dist var word
    range var word
    w1 con 35 ' alarm range value,change for your own use
    inches CON 13 'Assigns the value 13 conversion
    pause 2000 'wait for lcd to initialize

    sonar:
    pulsout portb.0,20
    pulsin portb.0,1,range
    dist = (range/inches) 'Converts raw sonar reading to inches
    LCDOUT $FE,1,"Distance"
    LCDOUT $FE,$14,#dist
    if dist < w1 then alarm 'alarm distance
    PAUSE 1000
    GOTO sonar
    alarm:
    sound portc.0,[100,50] 'buzzer connected to RC0
    goto sonar
    END

  21. #21
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    You got PWRTE whatever flavor of powerup timer enable in your config statement ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  22. #22
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi,

    As this card looks like an EasyPic 5 ...

    Which power source do you use ???

    and ... Disabling the Brownout feature ( default enabled ...) could be an idea.

    BTW ... What about the Master Clear pin ???

    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 " !!!
    *****************************************

  23. #23
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default

    Yeah, Alain got me on the turn...

    Have you connected somewhere the MCLR pin?

    Ioannis

  24. #24
    Join Date
    Aug 2008
    Posts
    42


    Did you find this post helpful? Yes | No

    Smile Hurrah!!

    O.K., I disabled the mclr in my fuse configuration and that did the trick. Brownout voltage could not be turned off, only changed from 4.0 v to 2.1 v. I also tried pwrte but,no luck. Anyhow thanks to all, I could find nowhere else that dealt with the Ping module and specific code to interface with a PIC mcu.
    Now anyone that wants to incorporate this sensor into a robotics or alarm project has access to some code that will work, or give a starting point for writing their own. Now, I wonder if I can spin the Ping module with a motor and have a quasi radar system ........


    Those who never dream, never will.

Similar Threads

  1. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  2. PWM Pulse Amplitude on 16F877
    By jrudd in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2009, 07:24
  3. Pulsin within subroutine
    By Wesley in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th January 2009, 23:05
  4. Replies: 3
    Last Post: - 13th September 2008, 17:40
  5. How to generate sine PWM using 16f877
    By kvrajasekar in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th September 2008, 08:40

Members who have read this thread : 1

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