newbie Q - edge detection?


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    RMCRAVEN's Avatar
    RMCRAVEN Guest

    Default newbie Q - edge detection?

    Hello

    I'm looking through the PB Pro manual, trying to work out how to detect a rising edge on a port input (for a PIC such as a 16F628, for example).

    I want to detect edges rather than levels - rising and falling - on inputs and generate output pulses which occur as a result. The inputs will be (0V-->+5V) or (+5V-->0V) transitions, derived from TTL or CMOS input pulses or clocks etc.

    By the way, I realise that there'll be some propagation delay through the PIC due to machine cycles etc. but that's not a problem - a few us in a few tens of ms is a small per cent delay. I should also note that I realise that I can differentiate the input with hardware in order to provide a narrow pulse and measure it with PULSEIN etc - I want to see if it can all be done in firmware though.

    Can anyone suggest how to build a routine in PBPro? I can't see from the commands in front of me how to go about it (I am assured it is possible in ASM but that's a bit ambitious for me at the moment).

    Cheers for any pointers - I'm having fun at the moment downloading example .BAS files and compiling them to the hex and ASM results, in an atttempt to relate the assembler listing to the basic source.

    RMC, England
    Last edited by RMCRAVEN; - 29th September 2006 at 23:49.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    look in the datasheet about Interrupts on change... on some PORTB i/o
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Interrupts are the best way, but if you can't use those you can do it as follows:






    TopOfLoop:

    If Old.Y ^ PortX.Y > 0 THEN
    Old.Y = PortX.Y
    IF PortX.Y = 1 THEN GOTO DoSomething
    ENDIF
    GOTO TopOfLoop


    DoSomething:



    The program loops and tests the port bit against a saved value using
    the bitwise exclusive OR. If the saved value is different, then "Old"
    is set equal to the port bit. Only when the Port bit has switched from
    "0" to "1" will it jump out of the loop.
    Charles Linquist

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Thumbs up

    If you need to detect say only one or two pins on falling (or rising edge), then you may want to use timers in counter mode. Should work for you.

    Then have a check like

    Code:
    IF TMR0=1 THEN 'TMR0 is either on falling or rising edge as you need.
    TMR0=0
    GOSUB GET_PIZZA
    ENDIF
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

  6. #6
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    I know you're new to PICBasic but you may want to take a look here:

    http://ww1.microchip.com/downloads/e...Doc/41214a.pdf

    Read through this document and see if anything in there is close to what you were looking for. If so the Capture/Compare/PWM module in the pic is what you will want to use.

  7. #7
    RMCRAVEN's Avatar
    RMCRAVEN Guest


    Did you find this post helpful? Yes | No

    Default

    Many thanks for the varied and detailed replies. I've downloaded the PDFs as recommended and I am trying to make sense of the info therein. I do appreciate the replies and I was hoping to be able to embrace some of the information, but ...

    I have a question relating to the learning curve - could someone have a look through the following prose and let me know if I should pack it in or persevere please?

    Now is the time for me to admit that I have spent at least 3-4 hours most evenings for the last fortnight trying to compile something that I can understand. So far, all I have managed is to modify an example program to get a couple of buttons to latch a couple of LEDs and a third button to switch them off. I estimate a total of about 30 hours of my effort to get to this stage.

    I had a choice of PicBasic or C or ASM and I chose what I hoped would be the easiest. I think I made the right choice but I am also beginning to think that even Basic is beyond me.

    I have tried drawing a flowchart of what I need - it helped slightly but the fundamental problem is one of understanding the Basic commands. Here are my observations regarding my own dismal progress:

    1) Things like (for example) the BUTTON command don't seem to behave the way I expect them to behave.

    2)How on earth anyone ever follows more than one for..next loop, especially nested ones, is beyond me.

    3) More than one variable? How do you ever keep track of it in your mind, or even by using loads of diagrams and paperwork?

    4) Conditionals such as If..then..else doesn't seem to work - I can see the "if" and "then" parts but the "else" seems to be missing in most examples, or at least the "flow" of the program appears incongruous.

    There are a dozen applications for PICs that even I can see should be simple to arrive at (relating to MIDI and aspects of analogue electronic music in particular - trigger generators, clock dividers, interfaces and so on) but the time is approaching for me to throw in the towel.

    I had thought that I should see some useful prgoress in two weeks ! Perhaps I should invest in some books - can anyone recommend an ideal title for someone who has ZERO programming skill?

Similar Threads

  1. mS Timer
    By whmeade10 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th September 2020, 13:12
  2. Newbie making an ignition timer
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 5th August 2012, 18:45
  3. RC Servo decoding/encoding using 12F683
    By ScaleRobotics in forum Code Examples
    Replies: 13
    Last Post: - 14th September 2010, 01:49
  4. Phase failure detection
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th January 2007, 01:53
  5. Auto Baud Rate Detection
    By mytekcontrols in forum Serial
    Replies: 10
    Last Post: - 31st October 2005, 03:17

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