40Mhz pulse counting and storing count value

Discussion in 'Embedded Systems and Microcontrollers' started by Madhava, Jan 12, 2015.

  1. Madhava

    Thread Starter New Member

    Jan 12, 2015
    5
    0
    I need to count 40 Mhz continuous pulse for every 100 microseconds and store the count in micro SD card before next cycle starts. The process should run for 24 hours.

    I am planning to use Raspberry pi since it's base frequency is 700 Mhz. It is possible to do?

    If not, please suggest any other solution to do the same.
     
  2. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    There is a trick which can do this with a PIC whose cycle clock rate is only ~20Mhz. The counting rate of the external-events Timer-prescaler is made of logic cells that can count at ~50Mhz. The Timer is started and stopped at the instruction rate (your 10Khz sample rate), and then stored before the next cycle begins.

    The PIC program never deals with the 40MHz events on an event-by-event basis. All it has to do is start/stop the counting process. The counting is done by the Timer hardware, which can be clocked at 40Mhz.
     
  3. Madhava

    Thread Starter New Member

    Jan 12, 2015
    5
    0
    Tha
    Thank you sir for your valuable reply. But i have a boubt that since i have to store the data in micro SD ,i have to interface the SD card module externally and writting to it may take sometime during i may lose a cycle count.
     
  4. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    I suggest that the only way to not to loose new events while storing the previous count is to do the counting in hardware (a real 40MHz binary counter), and then latch the new count in a real hardware latch. Then you will have 100us to unload the latch and store it to SD, while the real counter accumulates a new cycle of counts. Even a 700Mhz processor will not be able to save the previous count in the time the next event comes along...
     
  5. Madhava

    Thread Starter New Member

    Jan 12, 2015
    5
    0
    Is 40MHz
    Is 40Mhz binary counters will be available .?
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
  7. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    74S161 will count up to70Mhz.

    40,000,000events/s * 100e-6s/interval = 4000events/interval

    You will need a 12bit binary counter, which overflows after 4096 counts.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Something like a 74HC590 counter (it's 8 bit, use two) is spec'd to work up to 62 MHz so speed is not the issue.

    But it takes time to read the count, so unless you can ignore samples during that period when the count is stopped you will need 2 counter sets and ping-pong the outputs (while one is counting the other is being read).

    However, you are leaving yourself just .001 seconds between readings to store them on the SD. Perhaps you can package up say one second's worth of readings and store to the SD at a slower rate.
     
  9. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    Ernie,

    I already gave him an approach where he will not loose any counts if he can write a 12bit value (2 bytes) to the SD card in 100us.
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    When storing multiple bytes you encounter the age old problem of possible errors when a lower counter is about to overflow.
    The only solution I can think of at the moment is to inhibit the clock while you latch the data from all counters.
     
  11. Madhava

    Thread Starter New Member

    Jan 12, 2015
    5
    0
    Thanks for yours suggestions. I will try to do.. If i encounter any problem, i will need your advice ..in future..

    Thanks once again
     
  12. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    The counter being discussed is a 12 bit synchronous counter, so the bits that are going to change on any given new count edge all change more-or-less simultaneously. Latching the count into a parallel-loaded latch register takes only a fraction of a 40MHz period, so at most 1 event might not get added to the counter during the time its value is being latched.

    I would not reset the 12bit counting register after its value is latched; rather I would let it keep counting forward from its last latched value. It will modulo at 4096, so the values in the SD card would be periodic snapshots of the counter value every 100us. The number of counts that occurred in each 100us counting interval could be computed after the fact by subtracting the SD card samples (taking into consideration the modulo arithmetic).
     
  13. Madhava

    Thread Starter New Member

    Jan 12, 2015
    5
    0
    I understood thanks
     
Loading...