Issue with ATtiny 85 and my Foxhunt transmitter code

Hi guys,

I'm a member of an amateur radio group and I'm working in conjunction with another club member on what's called a foxhunt transmitter. My friend is working on a small transmitter circuit while I am working on the logic side of things.

Basically I've got a circuit which uses an ATtiny85 to put the transmitter into transmit via an optical isolator and then the ATtiny, using PWM, plays a morse ident followed by some melodies before finishing off with the morse ident again.

The problem I'm having is that everything works great when I only call two of the melody functions. As soon as I call the third melody function into the loop the program goes mad and just plays the first morse ident followed by the first melody and then finally the last morse ident. It totally skips melodies two and three altogether and I can't for the life of me see why when each melody function is constructed identically.

One thing I should point out was that when building and compiling the third function and attempting to upload to the ATtiny, the arduino IDE threw a fit and generated a long error message which I googled and found the cure was to replace the ld.exe with a newer one (if that helps solve any of this).

Also I had issues at first with the ATtiny not generating tones so I googled around and found I needed a different core to the one I was using so the one I am now using sets the ATtiny to run at 8MHz internal with BOD disabled. Using this core cured the no tone issue.

Since this is only an early prototype the code isn't as optimised as it could be, there are a lot of repeats which I plan to iron out when I've got things working as I want.

Had to post code on pastebin due to character limitations on this board...

Any help would be greatly appreciated!!!!

Many thanks!

Sorry for stupid suggestion.
But have you tried to call MelodyOne() instead MelodyThree() ?
MelodyOne() work, so if you call for third the same function I hope will work. So error is in the MelodyThree() function.
But if not work can be an error about timing. Is only a suggestion.

I think you are running out of static ram. On a Nano, your code plays all three melodies.
If you make the data for melodies global, the code to play the melodies won't require so much stack space.
There are also better ways to generate the morse code.

Pete