Speed problem on i/o board
Hi,
I need to measure 2 frequency's of max 2 KHz.
After discovering the i/o board has only 1 interrupt for all 8 inputs I am left to measure the freqs by polling... Theoretically no problem, as I need to poll at least 2x as fast as my frequency.. so 2 x 2 KHz x 2 sensors makes 8 Khz and the specsheet says it shoud do 10 Khz.
However, I haven't been able to reach that speed... Please tell me how I can speed up this sketch..
Till now the max measured frequency is about 1380 Hz.. which about 13 % of the advertized speed :-( (But probably has to do with me being a newbee and not fully understanding....)
#include <Wire.h>
#include <Indio.h>
volatile unsigned long runsCount; // ;-)
unsigned long lastMeasurement = 0; // keeps track of last time the screen was redrawn
void setup() {
Indio.digitalMode(7, INPUT); // Set CH7 as an input
Indio.digitalMode(8, OUTPUT);
Indio.digitalWrite(8, HIGH); // To work around a bug showing all digital input's as 1, only when externally powered
}
void loop() {
runsCount ++;
Indio.digitalRead(7);
if ((millis() - lastMeasurement) > 10000) // Measuring for 10 seconds befor displaying results, to minimize the inpact of Serial.print on the measurement.
{
Serial.print(runsCount/10); // Devide by 10 seconds to display number of runs per second
Serial.print("\r\n");
lastMeasurement = millis();
runsCount = 0;
}
}
Thanx,
Peter.
Hi Peter,
The 10Khz input speed was actually tested with the global channel interrupt and one channel... I agree we should clarify this in the datasheet.
Could you please try using the interrupt as in the bottom sample code on this page, but read the actual two sensor pins in your ISR to determine which one triggered the interrupt. I think this should still be faster than continuous polling.: https://industruino.com/forum/help-1/question/indio-digital-input-interrupt-usage-31
If you are using 32u4 topboard the expander's interrupt pin is connected to PCINT4 and you can follow the afforementioned code. If you are using the 1286 topboard the expander's interrupt pin is connect to INT7, and you can use the more simple "attachInterrupt(7, ISR, CHANGE);" command to attach the interrupt.
Let me know if you have any further questions.
Best Regards,
Loic
Your answer
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
Keep Informed
About This Forum
This community is for professionals and enthusiasts of our products and services.
Read GuidelinesQuestion tools
Stats
Asked: 10/8/15, 11:04 AM |
Seen: 3911 times |
Last updated: 10/9/15, 4:53 PM |
Update: After upping the I2c speed from 100 to 400 Khz following this post: http://forum.arduino.cc/index.php?topic=16793.0 The newly measured speed is about 3565 Hz, which is better but not enough yet...