PIC - receive data while pulsing pin from low to high and from high to low


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: PIC - receive data while pulsing pin from low to high and from high to low

    Thank you very much for pointing me to DT Interrupts. Much to learn, useful examples, a lot of help for future work. Unfortunately those procedures work with a fixed frequency. New frequency means recompile, reprogram and power up. Changes in frequency while running do not work. This is pointed in the examples.

    Then I tried to split the pulse time (miliseconds, var WORD) in pulse.byte0 + 256 x pulse.byte1. Calculated period in miliseconds and period in microseconds, applied the delay. Still trouble calculating the period, too many clock cycles lost with DIV and DIV32. I gave up.

    Master board now sends the period directly. No more period calculated from given frequency, no precision wasted with DIV and DIV32.
    Problem solved.

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: PIC - receive data while pulsing pin from low to high and from high to low

    Ideas:

    (Note my 16F877 datasheet is not recent)

    Port B has interrupt on change feature, page 132 of 218. I would use that port to check for transitions.

    The 16F877 has 3 timers, I would use one for low-high transitions and another for high-low.

    When port B senses a change, check if going high or low and start the appropriate timer.

    At next port B change, check which transition it is, then check if you started that timer, and if yes then check the time elapsed on the timer.

    If at the desired frequency, stop timer and trigger whatever event you want, or restart timer again. This way you can check going high and low transitions at the same time. You can check if within a range of desired frequency also, possibly a 5% tolerance - depends on your needs. You can also use a counter to check how many pulses was detected at that frequency (stability test - reset if less than X transistions).

    It may be a simplified approach, but it may be all you need for your application. You can use DT INTERRUPTS to control the timers (it can control a LOT of things), it makes things so much easier than trying to figure what registers to set in the datasheet.

    About DT interrupts, make sure you use the version for 16F PICs from DT's site (it's all labelled properly).

    If the maximum oscillator speed of 20 MHz of the 16F877 is not enough, consider an 18F. I used the 16F628 and 16F877 when I first started, now I use the 18F24K22 series, they can run at 64 MHz on internal oscillator.

    One last note, don't try to do everything at once. Start with one part of your logic, and build on it as you prove it works. Test each new section as you add them. Personally, I test them individually in small programs, then incorporate them in the main program as they are tested OK.

    Good luck!

    Robert

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: PIC - receive data while pulsing pin from low to high and from high to low

    Quote Originally Posted by skaarj View Post
    ... Unfortunately those procedures work with a fixed frequency. New frequency means recompile, reprogram and power up. Changes in frequency while running do not work. This is pointed in the examples.
    ...
    About this, if you use a variable instead of constant when you check the elapsed time on a timer, you can change the value of this variable within your program, no need to recompile.

    A simple method is INCREASE and DECREASE buttons than can change the value of your variable. Start at a default value, then an LCD is practical to display the new value of the variable. Using multiple pairs of buttons make changes easier; one pair for change of 1, one pair for 10, one pair for 100, whatever your needs are.

    You might only need buttons that set at specific values.

    Robert

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: PIC - receive data while pulsing pin from low to high and from high to low

    Hi,
    I might be missing something here but where does IOC fit in?
    The tast is to generate pulses with a specific and precise delay during which the ADC measurements will performed. There's no pulses comming into the PIC as far as I understand.

    Can you be a little more specific on the dynamic range of the output frequency? You mention 1-3000Hz down to 3 decimal places, is that a hard requirement? (I haven't crunched any numbers yet but I don't think that's doable).

    Here's what I'm thinking:
    * Calculate a suitable timer prescaler and timer value for the needed delay and set the timer up accordingly
    * Set output high
    * Start the timer
    * Go do the ADC conversion and output result.
    * Poll timer interrupt flag in tight loop
    * Set output low
    * Stop timer, reload value for correct delay, restart
    * Go do the ADC coversion and output result
    * Poll timer interrupt flag in tight loop
    * Rince and repeat.

    The issue here is that with a very low frequency (1Hz) there might not be enough bits in the timer/prescaler and you'd have to resort to counting multiple overflows (very doable but adds a bit of complexity). At the other end of the spectrum (3000Hz) there won't be enough resolution to resolve 2999.998 or 2999.999Hz. In fact, there probably won't be at the low end either.

    Finally, DT-Ints is in no way restricted to "fixed frequency". Perhaps the examples shown is USING a fixed frequency but that's not the same thing. Anyway, I think DT-Ints is probably overkill and will add unneccesary overhead for the requirements stated.

    /Henrik.

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: PIC - receive data while pulsing pin from low to high and from high to low

    I think you are right Henrik. I read too much in this:

    This is garbage but at least I have a variable pulse and I can do measurements between pin going from low to high and from high to low.
    Post 1 only mentions from 1 to 10Hz pulse out, very doable on 16F877.

    Robert

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: PIC - receive data while pulsing pin from low to high and from high to low

    Hi Robert,
    You are correct. I misread 3.000 as 3000, duh....
    Well, then perhaps its doable after all.

    /Henrik.

Similar Threads

  1. suggestions on reading a pulsing vehicle speed sensor?
    By droptail in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd June 2010, 17:27
  2. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 10:38
  3. Receive serial data
    By ruijc in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 7th August 2008, 22:52
  4. send and receive data using pic 16f84a
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2006, 20:12
  5. send and receive data using pic 16f84a
    By PoTeToJB in forum Serial
    Replies: 1
    Last Post: - 25th February 2006, 14:47

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