I'm considering a project that may result in more fast inputs than I can handle with interupts, so I was thinking I'd use a counter to count the pulses, and then a multiplexer to read those inputs?
I am new at the whole hardware side of things, so pardon any obvious schoolboy errors - I am here to learn!
I was thinking of having 10 counters (like a 7-bit ripple counter), feeding into 7 multiplexers. The problem with this approach is that I'll end up with dozens of links between all the multiplexers and the counters, there must be a better way?
What's the sane, grown-up way of turning ten 7-bit inputs, into just one 7-bit input?
Currently I don't even know what to Google for, so any hints would be appreciated
Not that hard - go to ti.com and search for "counter" 8)
Here's an example, 8-bit counter
This one is nice because it also has tri-state outputs, so you can put many in parallel and only turn on the output of the one you want to read.
So put your seven in parallel, control the logic to enable counting for your time period, then 1 at a time enable the outputs, capture that output with a parallel-load/serial shift-out register such as 74AC299 and read the results.
Then control the logic again to clear them.
As far as building - wirewrap, will go together quick.
Oh, that sounds good. So with the tri-state, do you mean it is as simple as connecting all the "first-bit" pins together, all the "second-bit" pins, and so on, and making sure that only one chip is "enabled" for output? All the others would then be "not connected"?
The schenanigans would then just be to manage the "one and only one is live" bit (not too difficult with a shift-register for example)
The parallel-in, serial out shift-registers is a great spot - I read about them before, but completely forgot about it.
Yes.
"All the others would then be "not connected"?"
That's one way to envision them. More correctly, their output drivers are turned off, akin to the arduino pins being selected as input pins.
Yes, serial-in/parallel-out shift register to control who is active would work nicely.
Thanks for the tips. I'll get all this running off one pin yet
Time to go and get a few components and play around with shift-registers, counters and whatnot, before going crazy and building a plate of spaghetti...
Actually, considering the really low time-resolution required*, could I just connect one input pin to all 10 fan-sensors leads via a selector or whatever, and just do something like
Connect Pin X to Sensor F1
Count pulses for a few millis
Connect Pin X to Sensor F2
Count pulses for a few millis
...
I expect pulses to come every 10ms to 40ms if it's one-per-rev, or half that if it's two-per-rev. I'm new to all this microprocessor mallarkey, so have no idea what a practical limit is on counting pulses in a tight loop, or if that's even the right way of doing it.
Here's a bit of made-up, untested, pseudo-code to explain what I mean:
void loop()
{
for (i = 0; i < MAX_FAN_SENSORS; i++)
{
SelectFanSenseInput(i);
GetFanPulseCount();
}
}
void SelectFanSenseInput()
{
// magic happens here to tell the multiplexer to
// connect the correct fan sensor to the sense pin
}
int GetFanPulseCount(SensePin)
{
unsigned long senseTime = 0;
unsigned long endTime = 0;
unsigned long duration = 0;
int fanPulseCount = 0;
senseTime = millis();
endTime = senseTime + 500;
fanPulseCount = 0;
while (senseTime < endTime)
{
// spin waiting for a pulse to come
duration = pulseIn(FAN_SENSE_PIN, HIGH);
if (duration > 0)
{
fanPulseCount++;
}
senseTime = millis();
}
Serial.print("Fan ");
Serial.print(SensePin);
Serial.print(" = ");
Serial.println(fanPulseCount);
}
Oh, I guess I missed the point in the other thread where you mentioned how relatively slow the signals will be coming in, I had it in my head that it would be on the order of thousands a second for each fan.
The major difficulty I can see with your latest idea for a plan is the long period between rotations. If you are rotating through all you fans and taking half a second to collect pulses (I assume this is to up resolution on your speed data) by the time you get back to the first fan its 3.5 seconds later and any kind of control loop is going to work better if you can get it looping tighter.
You ultimately looking for speed, so counts per unit time. You can either keep track for a set time like you are doing then see how many counts came in or you keep track of the amount of time it takes for one tick to happen and then divide 1/T for the speed during that tick.
This has the advantage of increasing speed data resolution over shorter sampling periods. Some nice info for you to know would be how long the tach pulses last, as that might affect your software. If its encouraging I've been able to get two quadrature encoders processing ~1500 counts per second each without using external interrupts at all so I think this is doable as the software is somewhat simpler without the quad decoding. What does your I/O pin budget look like?
I think that using multiplexing, parallel-in-serial-out and/or tri-state counters, my pin budget for sending should be fairly low. I have yet to start a thread on how to control the ten fans.
Haven't looked at that yet - expect a post on ten-way PWM or latched variable voltage, or whatever makes a pc fan spin
Fairly confident that I can nail this sending issue though, thanks to all the patient help here. Time to order some bits and try it out!
Hi Techies, I am planning to connect around 500 analog sensors with less than few volts from 100 to 200 feet, also I want to identify each sensor. There is no address currently available with the sensor. any idea? Response is appreciated.
500 sensors? What's the data you are gathering?
That is gonna be a lot of multiplexers. How fast are you planning on sampling?
If using a '328 based Arduino, which has 6 analog inputs, you could have a 1 of 8 mux on each input (use just 6), each connected to six 1 of 16 muxes, for a total of 576 input channels, set up to sample 6 at a time.
conceptual code:
array value [576]; // = 6 * 16 * 6, counted from 0 to 575
void loop(){
for (upper_select = 0 to 15){ // cycle thru the outer 16 muxes connected to actual signals
for (inner_select = 0 to 5){ // cycle thru the 1 of 6 muxes connected to each analog channel
for (analog_select = 0 to 5){ // cycle thru the arduino analog channel pins
value(upper_select*15 +inner_select*5 + analog_select *5) = readAnalog(analog_select);
value(upper_select*15 +inner_select*5 + analog_select *5) = readAnalog(analog_select); // ignore 1st one, give analog data a chance to settle
next analog_select; }
next inner_select; }
next upper_select; }
Oh multiplexing many inputs, that means one input many output. Sounds interesting I haven't heard this before. How the things can be done. If I have many inputs on the screen then it combines all the input and display only one single output, is that so. Please clear my concept.
Thank U so much. Data is coming from various sensors devices and couple of them from a distance measuring ultrasonic sensors. sample size will be one reading per 30 minutes or an hour from each sensor. There are many Mux available in the market, I appreciate if you suggest a good one for relaibility.I spent some time to search but could not find a low priced Ultrasonic sensors that can measure a distance of 18 foot (6 meters). Many of them starts with more than $50.Your time is appreciated.
This is to network many devices at home. I mentioned 500 and that is maximum, May start with 100 and then will expand if required.
@Bretjsarena4a,
Multiplexing in this case means one input (the ADC in the ATmega) reading many output sources.
Demultpexing would mean one output going out to many input sources.
You could have the ATMega doing the ADC conversions and sending a steady stream of messages to your PC with 4 bytes of information:
2 bytes that represent the 0 to 575 address in 10 bits and the other 6 representing a "data message" indicator or something, then 2 bytes that are the 0-1023 data from the ADC.
How you represent that on the screen is up to you.
@detroitselvam,
The CD4051 is a popular 8 channel analog mux
This part from Analog Devices is an example of a 16 channel analog mux
The DG406 is another 16 channel mux
You will have to read the datasheets, understand the little bit of resistance each will present to your signal and decide what is acceptable.
The voltage presented at the ADC input must be 0-5V, if you have more than that you will need something like resister voltage dividers to bring the level from your sensor down.
You will need the 6 analog inputs, 3 address lines for the 4051, 4 address lines for the DG406 or equivalent.