How to get two 14M2 chips to synch and play tunes together?

As part of learning about the PicAxe, I've been tinkering with using two Picaxe 14M2 chips to play a song using the tune command. I programmed a "master" chip to play the melody and a "slave" chip to play the harmony. I thought I could use a single wire going from one chip to the other to synchronize the two chips and everything would be okay, but sometimes on power-up, the two parts start off at different times. It's a simple children's song that is played fairly slowly, so I'm surprised my simple synch line isn't good enough to get it to work. Is there something fundamental about the Picaxe I should know to get this to work?

Both chips use the same +V and ground. I've been testing these with the PC disconnected. Sometimes it works perfectly, but about a third of the time it's off.

I delay the Master chip to give the power supply plenty of time (about 2 seconds) to stabilize. I give the slave chip about 4 seconds worth of waiting around for the Master before the slave jumps to a subroutine and starts playing anyway.

Is there any way to make this work right every time? Thanks.

Code:
;For the 14M2 picaxe.
;After power up, this waits about 2 seconds then sets
;Pin C.2 (Physical pin 5) High to synch all the other chips.

Main: 

Pause 2000 ;Wait for everyone to power up.
High C.2 ;Set the synch line high.

GoSub Jingle

END

The slave works like this:

Code:
Symbol BowDownTime = w0 ;Caution WORD sized uses up b0 and b1!
Symbol Counter = w1 ;Caution WORD sized uses up b2 and b3!

;Chip will behave like a slave for BowDownTime counts...
BowDownTime = 4100 ;Caution WORD sized! Do not exceed 65000!!!

Main:

For Counter = 1 to BowDownTime
  IF pinC.2 = 1 THEN GoSub Jingle
Pause 1 
NEXT Counter
 
;If a Synch signal did not get detected on C.3, then play anyway... 
High C.2 ;Set the synch line high.
GoSub Jingle 
  
END
 

KeithRB

Senior Member
Use the sound command and synchronise each note.

I imagine that noise or something is causing variable length pauses while listening for a new download command.

Do you have the download cable hooked up to either chip? try removing it.
 

Technical

Technical Support
Staff member
The fundamental issue is the pause 1 in the slave's for..next loop. Basically this means , if the master happens to do the high just after the if.. line has been tested, there is a whole millisecond delay before the slave next tests the input pin. This will introduce a offset you don't want.

Hope there is a resistor between the two chips, do you really mean for the slave to test for an input on C.2 and then make C.2 an output (high) as well - could mean both chips trying to drive the same pin high?
 
Use the sound command and synchronise each note....
I guess that would be okay but then I couldn't use all the nifty tools available with the tune command, which provides specific musical notes of specific durations, etc.


...
Do you have the download cable hooked up to either chip? try removing it.
No cables are connected to the units. It's a very good point, however, because I noticed that having the PC hooked up does cause even longer delays.
 
The fundamental issue is the pause 1 in the slave's for..next loop. Basically this means , if the master happens to do the high just after the if.. line has been tested, there is a whole millisecond delay before the slave next tests the input pin. This will introduce a offset you don't want.

Hope there is a resistor between the two chips, do you really mean for the slave to test for an input on C.2 and then make C.2 an output (high) as well - could mean both chips trying to drive the same pin high?
I don't think I would notice a 1 msec delay. The delay is probably more like roughly 0.2 seconds or more.
I see your point about the C.2 resistor, just for safety. But that doesn't seem to be the source of the delay, would it?
I've been wondering if it might have something to do with the time granularity of the tune command. Or does the PicAxe do something in the background after power up that causes hidden delays?
 

Technical

Technical Support
Staff member
Or does the PicAxe do something in the background after power up that causes hidden delays?
No.
Can we see your whole program, including the sub procedures?
And we assume the circuit is correct e.g. no rogue floating serin pins etc?
 
Top