A large file can be attached (click the REPLY button and look just below the text input field).
Do you use Arduino Uno for all the Slaves ?
Do they work well with the 3.3V I2C bus of the Teensy 3.1 ? Do you use a level shifter ? Do you check if the I2C transfer was succesfull.
What about the photo interruptor ? How do you use it ? Do you filter the output ?
Oops will use attach next time.
Yes Arduino is used for all the Slaves 5 total. I don't use a level shifter, same power supply (+5v) used to power up the Arduinos and Teensy; and the I2C are connected together for all Arduinos and Teensy with 4.7 Kohm resistors to +5V on the power rail.
Had no issues with the I2C transfers and verified that the data was correct by having a counter on each Uno and the data via I2C was correct on the Teensy.
I'll sketch how I connected the Pulse, Data and Direction in another post. Pulse and Photointerrupter go thru an OpAmp then a schmitt trigger. The Direction goes thru a 4N35 then also thru a schmitt trigger.
Is this what you mean as filtering?
The H21A_void() is large for a 13KHz interrupt handler.
The Arduino can do bytes fast, but longs are slow. Could you do a part of the calculation in the loop() ?
Do you have an oscilloscope ? It is possible to change an output pin in 2 clock cycli, which can be used to measure the time of the interrupt.
can't compress the ISR's anymore, the only way is if I have an additional interrupt for the Direction Pin, if I poll it in the loop part, you may loose data as direction could change anytime.
Can't call it an oscilloscope its the Xprotolab plain :relaxed:
I don't quite understand the last sentence (change an output pin in 2 clock cycli) really sorry didn't get that.
Some variables of the interrupt handlers are use in the loop(). That is no problem for a byte, but it is problem for an integer and long. They are read and written byte by byte.
While the code is busy with an integer or long, an interrupt could occur right in between that reading or writing of the bytes.
You not only have to use 'volatile', but you also have to disable interrupts in the loop() when you do something with those integers and longs.
thanks on the advise, will try to do some re-coding to avoid the longs. But if I disable interrupts in the loop, I will loose pulses even more.
We use the name "requestEvent()" for the I2C interrupt handler ::)
Your "send_i2c_data()" is definitely too slow.
Please don't use a String object there. Allocating a new object and using it is slow.
If possible transmit binary data, not a readable string. It can be an array of floats, or a struct.
When the loop() is optimized, the "requestEvent()" only needs one code line: Wire.write( (byte *) myDataArray , sizeof ( myDataArray )) ;
:grin: Ok noted.
After many previous trials this was the only way I could successfully transmit the data via I2C in string format. Seems I need to do more reading and researching, I understand what you are getting to, If I manage to get the ISR's faster and the I2C ISR also more efficient, I will loose less if not any pulses. But the issue still remains if one ISR is running, the other interrupts are disabled, meaning I might loose less data, but will not ensure all the data is gathered by the Uno.
I don't understand which part of the 'dgt_arr' array is transferred via I2C. The complete array is 120 bytes, that is too much. The buffer inside the Wire library is only 32 byte.
Ok, data I am sending is in the val_arr [0-5] thats 6 integers; 6 integers x 5 digits each is 30 bytes.
I am converting the above array (val_arr) to (dgt_arr) in the loop. this is why I have an additional index [arr_rdy]; this is only "0" or "1". Hence, in the loop if I am filling the arr_rdy = 0 if I2C is called it sends the other one thats the "1" and when i am filling the "1" the "0" is sent. Its just to make sure the data is not sent half way it is being filled then the numbers become jargon. better send the same data couple of times while the other set of data is being readied.
Hey man thanks a lot for the asisistance, will try to do some re-coding and changing the values to integer and bytes. I;ll post my update as I am getting it done.