Go Down

Topic: Time Multiplexing with arduino - Is digitalWrite fast enough (Read 181 times) previous topic - next topic

user_name1234

Background:
I am currently trying to figure out how to time multiplex signals with 2 separate 16 channel multiplexer. Each multiplexer has 9 inputs it switches through. I have read some stuff about how the digitalWrite() function is slow. I need to be able to switch inputs on each multiplexer (writing 8 digital pins 4 for each multiplexer) every 13.9 microseconds to get a sampling 72000 Hz(1/72000). So, I have two questions.


One is if the digitalWrite() function is fast enough to actually write 8 pins fast enough to time multiplex at the mentioned rate and time. If not how could I get around this, I have looked a little at port manipulation and was wondering if this was the correct way to do this if digitalWrite() is not fast enough?

Second question. I was planning on using the micros() function as a way to know when to switch. Is this a viable method or is it too slow or not accurate enough? Will the loop run fast enough to not miss the timing? Switching to get the data each time in is pretty imperative.

For example would something like this work?
Code: [Select]

void loop(){

if(micros()%13 == 0)
//write 8 pins

}


Thanks!

Grumpy_Mike

Not sure what you are trying to do but the digital write is very fast when compared with the analogue read you are using so it won't materially affect the speed of things.

If it were to be too slow in an other contex then yes port mapping would be the way to go.

Quote
Each multiplexer has 9 inputs it switches through.
And
Quote
f the digitalWrite() function is fast enough to actually write 8 pins fast enough
Do not make sense. If you have 8 inputs to a multiplexer you only need to write to 3 select pins and that number will do you for up to 16 inputs.

Note the micros delay only increments in steps of 4, so it will not give you precise timing.

Edit the more I look at this the more unclear I am about what you are trying to do and why.

user_name1234

Sorry for the confusing question. Hopefully this will clarify a bit. I am controlling two individual 16 channel multiplexers. Each one has 4 control pins making a total of 8 pins that I need to write to. I am time multiplexing, so I need to write to all 8 of these pins under a certain time period to make my multiplexer switch the input it is taking. My question is if anyone knows if the digital write function is fast enough to write 8 pins before the time I need to switch again (about 13 microseconds) has elapsed. I am not be using analogRead() in the loop just writing to 8 digital pins.


Also if micros() is not accurate enough does anyone know of another way that I can accompish this timing?

Thanks.




Grumpy_Mike

Quote
I am controlling two individual 16 channel multiplexers. Each one has 4 control pins making a total of 8 pins that I need to write to.
No you don't need to write to them individually you parallel up the addresses so you send the same address to each multiplexer. I am assuming that each multiplexer has a separate output that you are reading.

However, time division multiplexers don't work on free wheeling inputs, there must be some way of synchronising the received multiplexed stream so you know where to put the results that appear on the output of the multiplexer. You can't just have a fixed multiplex rate because no matter how accurate you may think the clock is the sending and receiving multiplexers will drift apart and you will be getting the wrong channels going to the wrong place.

A digitalWrite takes about 3uS.

user_name1234

Quote
No you don't need to write to them individually you parallel up the addresses so you send the same address to each multiplexer.
If I am understanding what you said correctly. You are saying that I need to map the pins so that. Is this correct? I am not sure if I can do that with the setup I have/ the idea I have in mind as I will be having to. I believe I can use port manipulation to write 8 pins at the same time to sync the outputs of the two multiplexers having the same effect.

Quote
You can't just have a fixed multiplex rate because no matter how accurate you may think the clock is the sending and receiving multiplexers will drift apart and you will be getting the wrong channels going to the wrong place.
I might need a little clarification on this part. It seems like you are saying that I cannot use a timing mechanism. What do you mean by not having a fixed multiplex rate? I am not exactly sure how exacltly how to do this with out some time keeping mechanism. By recieving stream, are you refrencing demultiplexing the signal?

Thanks!

Grumpy_Mike

Quote
You are saying that I need to map the pins so that. Is this correct?
So that what?
Quote
not sure if I can do that with the setup I have/ the idea I have in mind as I will be having to.
Having to do what?
All I am saying is that the multiplexer address pins for each multiplexer should be connected to same Arduino pins, so you will only need to write to 4 pins.

Quote
I believe I can use port manipulation to write 8 pins at the same time
On an Arduino Uno there is not 8 free pins that you can use. In other words not port has 8 free pins. It is different on a Mega.

Quote
It seems like you are saying that I cannot use a timing mechanism.
You can not simply rely on any system giving you a precise time interval in order to achieve TDM, be it on transmit or receive.  There must be something that synchronises the switching between transmitter and receiver.

Quote
By recieving stream, are you refrencing demultiplexing the signal?
Yes there is no point in sending a TDM signal if it can not be received and split into none TDM channels.

I do not understand what you are trying to achieve this sounds like a X-Y Problem

Go Up