-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fast Read/Write #2
Comments
Thanks for exhaustive comment! At the time i was also reaching out for speed - unsuccessfully it seems. But the machine is totally useful as it is - so i will drop the digitalWriteFast library for now. With your comments and code i might look into it again - or you might?! But maybe the digitalRead(), pinMode() and digotalWrite() arduino functions are fast enough. I think i remember also having some other issues regarding ps2.h library - and I somehow solved it with ps2bs.h Cheers! |
Hello I was able to reduce the time, adding this library "https://github.com/Locoduino/DIO2" ps2: Total Loop duration 9020 µs It is really fast, more than I expected. The simplest solution was to go back and use the original ps2 library, but creating two functions ... The first one, reads only 1 bytes from the trackpad and compares it with a decimal value (in my case, 128 not pressed and 160 pressed) The second, really when the trackpad is pressed (160 decimal) example: void TrackPad ()
{
Trackpad.write(0xeb); //Read Data
Trackpad.read();
mstat1 = Trackpad.read(); //State 1 enable/disable button on/off
// If the trackpad is pressed, then call the function to read all the full bytes
if (mstat1 == 160)
{
TrackPad_Enable ();
}
}
void TrackPad_Enable ()
{
Trackpad.write(0xeb); //Read Data
Trackpad.read();
mstat1 = Trackpad.read(); //State 1 enable/disable button on/off
mxy = Trackpad.read(); //Both Axis
mz = Trackpad.read(); //Pressure finger pressure value
mstat2 = Trackpad.read(); //State 2 different pad positions
mx = Trackpad.read(); //Axis X value
my = Trackpad.read(); //Axis Y value
// collect the bits for x and y
x = (((mstat2 & 0x10) << 8) | ((mxy & 0x0F) << 8) | mx );
y = (((mstat2 & 0x20) << 7) | ((mxy & 0xF0) << 4) | my );
z = mz;
//do an action and send midi message
} It is a simple but effective solution Anyway, if you want to see how I modify the ps2 library, tell me and I'll share it here ..... read very quickly but it doesn't work Thank you very much, regards |
Hello, how are you ... I'm using the PS2 library to control a trackpad, after seeing your code I used some functions and settings to be able to send midi messages. It works very well but I needed more speed in reading the trackpad, that's why I made a test code to measure how many cycles per second the "PS2" and "PS2bs" library takes ... but I have no good news.
With Arduino Mega:
ps2: 112 Cycles per Second
ps2bs: 103 Cycles per Second
I wanted to know if there is something I am doing wrong, but the library "digitalWriteFast" does not allow to use constants and that is why it works in a normal "slow" way.
For the test code I use the files:
Here is the code, I use the two libraries at the same time but I choose each one in line 15 and 16
//PS2 mouse(MOUSE_CLOCK, MOUSE_DATA); // usage: PS2 mouse(int clk, int data)
PS2bs mouse(MOUSE_CLOCK, MOUSE_DATA); // usage: PS2bs mouse(int clk, int data)
Thank you very much, regards
The text was updated successfully, but these errors were encountered: