Why is my piano so slow?

geezer88

Senior Member
I bought a PC keyboard at the local thrift store and hooked it up to a 28x2. I have a speaker wired to c.4. The following program is loaded:

EEPROM $00,(22,22,22,22,22,22,22,22,22,22,22,22,22,10,11,22)
EEPROM $10,(22,22,22,22,22,8,9,22,22,22,22,22,22,6,7,22)
EEPROM $20,(22,22,22,22,22,4,5,22,22,22,22,22,1,3,2,22)
EEPROM $30,(22,22,22,22,22,22,0,22,22,22,22,22,42,43,41,22)
EEPROM $40,(22,22,22,40,38,37,39,22,22,22,22,22,22,22,36,22)
EEPROM $50,(22,22,22,22,35,34,22,22,22,22,22,33,22,22,22,22)
EEPROM $60,(22,22,22,22,22,22,32,22,22,22,22,22,22,22,22,22)

begin:
kbin [10,begin],b0
read b0, b1
tune c.4, 6, (b1)
goto begin

This maps the keyboard to the first two octaves of the tune notes. Note that the keyboard keys to be used are the top row for white (BS-`) and the next row down for black. The whole keyboard is used upside down. This seems to make the most piano like arrangement. Well, sort of.

The program works, but some keys are very slow to respond. A normal PC keyboard responds pretty fast so I don't think that is the trouble. It seems to me the picaxe is slow somehow, but I can't see why. I did try using the timeout feature of kbin, setting the value at 10 millisec, but that didn't make any difference. Any ideas?

This was just an exercise in using the keyboard, and will not be developed further, so no error checking or any embellishments are included.

thanks,
tom
 

Jamster

Senior Member
I'm not 100% sure, but try using the sound command instead of the tune command, I have synths (well, nearly) that use that command and they seems to work flawlessly.

Jamster
 

Technical

Technical Support
Staff member
Every 10ms you are timing out and jumping back to the start. So your PICAXE spends most of its life jumping back to the start, which is unnecessary and slows its response to the keyboard.
Try changing

kbin [10,begin],b0

to

kbin b0
 

geezer88

Senior Member
I posted the wrong version of the program. The time out version posted was an experiment to see if the timeout would help. My original version used the "kbin b0" command. It did not seem to make any difference in the responsiveness of the system, if the timeout was in or out.

tom
 

geezer88

Senior Member
I'm not 100% sure, but try using the sound command instead of the tune command, I have synths (well, nearly) that use that command and they seems to work flawlessly.

Jamster
I'll give that a try. I went for the tune command because it had predefined notes.

tom
 

geezer88

Senior Member
I'll give that a try. I went for the tune command because it had predefined notes.

tom
I gave this a try. Using Excel and the formula given by others on this forum that calculates the value to use in sound for a particular frequency, I got as close as I could to the notes of the first two octaves. Using the same lookup table idea, but with sound values instead of tune values I get the same slow response. I'm betting at this point that the keyboard handling code in PixAxe is the bottleneck.

tom
 

hippy

Technical Support
Staff member
Try adding a 'KBLED $80" at the start of the program. That worked for me.
 

Technical

Technical Support
Staff member
Every keyboard press normally 'flashes' the 3 LEDs on the keyboard.
So the PICAXE detects key, turns LEDs on, waits a while, turns LEDs off.

The KBLED $80 turns this flashing function off, hence speeding up response as there are no delays in between the flashes.
 

geezer88

Senior Member
Ah, thanks for the help and explanation. That might be something to add to the next edit of the keyboard instructions.

tom
 
Top