Say I just wanna send a series of 101010101....... @ a frequency of 1MHz (synchronized by a 1MHz clock)
or something like the one in the diagram (I need at least 3 channels)
Since Serial and I2C has extra frame bits like start/end/ACK bits, it's not a good option.
I'm not sure if SPI or other libraries can do that?
Any suggestions? Thanks in advance.
If you just want to send an unending series of 1s and 0s just use digitalWrite(). However that is a slow function so you will probably need to use port manipulation to write directly to the I/O port.
Robin2:
If you just want to send an unending series of 1s and 0s just use digitalWrite(). However that is a slow function so you will probably need to use port manipulation to write directly to the I/O port.
...R
Paul_KD7HB:
Where is your "clock" signal coming from? I suggest using an interrupt from the clock signal to toggle the output pins.
Paul
Thanks for both of your ideas. So combining port manipulation and interrupt, I finally get something like this:
At 1 MHz on an Arduino UNO you only have 16 instruction cycles to do everything from interrupt handling to data output. The clock interrupt every 900-something microseconds will cause a glitch in your output about every millisecond.
johnwasser:
At 1 MHz on an Arduino UNO you only have 16 instruction cycles to do everything from interrupt handling to data output. The clock interrupt every 900-something microseconds will cause a glitch in your output about every millisecond.
It looks like your bit pattern is:
PB1-> 1011101110111011
PB2-> 1111111111111111
PB3-> 1010101010101010
So PB2 is just ON all the time, PB3 just toggles, and PB1 on 3 off 1 (offset by 1)?
That's just a sample. Actually I want a pattern like:
PB1:0101010101010101....(clock)
PB2:1111111111111111....(enable signal)
PB3:1111111111111111xxxx....(data[0])
PB4:0000000000000011xxxx....(data[1])
Since I don't care what the data xxxx is, I can just implement the first 16 bits (to have 8 pos-edges)and let it loop itself. As you suggest, the ISR block should be done within 16 instruction cycles, how about something like:
I'm not sure how IDE compiles it, but it looks like the above code goes beyond 16 cycles.
Because the clock signal with a period of 2 interrupts should be 500kHz, but the actual signal I measured has a maximum of 125kHz for the interrupt @ 1MHz,500kHz,250kHz.
Any suggestions on how to minimize the code? only need one signal to change from 0 to 1 on every 8th pos-edge, others signals are always the same.