Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to interface device using specific synchronous protocol that requires clock signal within 1..2MHz. Period instability shouldn't exceed 10%. Also, in certain condition protocol requres clock signal to be set into still high level. The whole circuit has two channels that act the same way (so I need to clock signals, etc.).

Can I use RPi to generate the signal accurate enough? RPi have only one PWM channel, but I need two of them. GPIO bitbang looks like solution, but usleep(1) shows ugly performance. It seems this could be solved by creating a driver (OMG!), or using some kernel tweak like Xenomai. But could I really reach accurate delay of 1us or even up to 500ns?

The other solution to me is to use external hardware clock generator, and perform interrupts-based data exchange. Can I reach desired performance at userspace?

share|improve this question

closed as too broad by goldilocks Jan 10 '15 at 11:57

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

One more approach: add a small microcontroller dedicated to serving the fast interface and talk to that over some serial bus. – XTL Jan 10 '13 at 9:33
Actually I'm trying to get rid of one. I had simple protocol implementation with AVR MCU, but it's not powerful enough to be used for full protocol implementation. – xtreye Jan 10 '13 at 9:40
Unfortunately, not. I refused to use RPi for the task and decided to port AVR code to generic ARM platform. And that's why: RPi-based solution would require the use of external clock or PWM in conjunction with interrupts handling. Another way is to use real-time kernel (Xenomai). At the same time "dull" port to ARM platform saves a lot time while meeting requirement. – xtreye Mar 15 '14 at 23:29