![]() |
Forum Index : Microcontroller and PC projects : CMM2 and sound
Author | Message | ||||
BitLost Newbie ![]() Joined: 07/08/2021 Location: New ZealandPosts: 15 |
First post. May I start by congratulating and thanking all who have brought the Maximites and MMBasic into existence. It's a quite extraordinary achievement. I built the original, monochrome Maximite, then the CMM2, both from Silicon Chip Magazine-approved kits. The CMM2 required the additional oscillator and cap. Retrofit looked near impossible, but it was surprisingly easy to add the components to the main board, once enough courage was available. I'm a pensioner, and a near-novice programmer, having last dabbled with BASIC back in the '80s, so I, not the CMM2, may be source of this problem: I can't get the CMM2 to produce sine waves reliably from within a program. PLAY TONE works from the command line, but not from within a program. A chain of PLAY TONE [with specified duration] commands also works, however, if separated by a PAUSE interval, the interval time seems to be triggered from the start, not the end of the played tone, which is unexpected. PLAY SOUND sort-of works within a program, but, when a sine wave is specified, it works only on its first call. However, square waves always work, whether first called, or called after either square or sine wave. I have apparently successfully upgraded to V5.07.01b4, from V5.06.00, from original V5.05.05, all via dfu-util. OPTION USBKEYBOARD setting was lost on upgrading, contrary to the manual's assurance that it wouldn't be. Is it possible that dfu-util is corrupting the firmware? If it is, I'm stuck: no Windoze in this house... Any ideas? Am I doing something stupid? (It has been known, and seems to be getting more frequent...) |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Welcome to the merry band. While options are usually maintained through updates, sometimes there have been changes to the layout of the option memory area. In those cases, you will need to reload your options. Regarding your issues with sound. Some example code that shows your problem will help us help you. One likely problem is the tones play in the background and your program will continue running while the tone is audible. If you want to time from the end of the tone, use an interrupt. Jim Edited 2021-08-08 12:44 by TassyJim VK7JH MMedit |
||||
BitLost Newbie ![]() Joined: 07/08/2021 Location: New ZealandPosts: 15 |
Well, at its simplest, PLAY TONE 256, 256, 1000 does what you'd expect, from the command prompt, but, if it's made into a single-command program, it's silent. Try this: PLAY SOUND 1, B, S, 512 PAUSE 1000 PLAY STOP PAUSE 1000 PLAY SOUND 1, B, S, 256 PAUSE 1000 PLAY STOP END Substitute Q for S, and vice-versa, one at a time, for each of the 4 possibilities, and hear the results. For me, Q then Q produces the two square waves. Q then S produces the square wave only. S then Q produces both sounds. S then S produces the first tone only. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Your program works perfectly for me on V5.07.01b4 all variants. AFAIK this code hasn't changed since 5.06.00 |
||||
BitLost Newbie ![]() Joined: 07/08/2021 Location: New ZealandPosts: 15 |
Thank you. Oh dear, where to from here? Corrupted firmware or hardware fault? I'll reset the thing and reload the firmware, again using dfu-util. Can we be sure that dfu-util isn't doing naughty things? Any ideas? |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Try and load the firmware as per the manual using CubeProgrammer |
||||
BitLost Newbie ![]() Joined: 07/08/2021 Location: New ZealandPosts: 15 |
OK, done that: V5.07.01b4, as before, to avoid introducing more variables. No change. ![]() Next suggestion? (I've already thought of hurling the thing at the wall... ![]() Edited 2021-08-10 13:54 by BitLost |
||||
BitLost Newbie ![]() Joined: 07/08/2021 Location: New ZealandPosts: 15 |
Addendum: possibly not quite 'no change'. The sound problem is unchanged, but OPTION USBKEYBOARD was not lost, unlike when I upgraded the firmware using dfu-util. Perhaps I should reset the thing fully, to clear the entire memory space - the button on the Waveshare board? |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
The button on the waveshare module just restarts the system, it will not clear any settings. To fully clear the system: OPTION RESET then shut down and remove the backup battery. wait a few minutes - about one stubby should do. reinstall the battery and switch on. Jim VK7JH MMedit |
||||
BitLost Newbie ![]() Joined: 07/08/2021 Location: New ZealandPosts: 15 |
Thanks TJ, will do that soon, if you think it'll be better than what I've just done. Before I saw your post, RTFM showed it was pointless pressing the Reset button, so, using CubeProgrammer, I erased entire chip and reloaded V5.07.01b4. No errors. OPTIONS erased, as expected. Sound? SNAFU. ![]() This is a real disappointment, because I built the thing, hoping to use it as a programmable sig gen for some acoustics experiments I've been wanting to do for years. Will probably take the stubby option anyway... |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
I can't think of any reason for your issue. Not able to replicate here. I doubt if there is a hardware fault because sound does work. I assume that you are getting both left and right? Try putting the volume parameter on the end of the PLAY SOUND commands 0 to 25 is the range. Try 15 - 20 PLAY SOUND 1, B, s, 512,15 PAUSE 1000 PLAY STOP PAUSE 1000 PLAY SOUND 1, B, S, 256,20 PAUSE 1000 PLAY STOP END We had better check the backup battery voltage What do you get with print pin("bat") Jim VK7JH MMedit |
||||
BitLost Newbie ![]() Joined: 07/08/2021 Location: New ZealandPosts: 15 |
PIN("BAT") returns 3.06V (rounded), so that seems OK, and the RTC works. I haven't yet checked system voltage - perhaps I should. Even with sound vol specified, the behaviour is the same. Yes, both channels (well, when it works...). Note the behaviour, as described in the third post - it's most bizzarre, because clearly PLAY SOUND x, B, S, y, z does sometimes work, but it's fussy about what has gone before, and it's repeatable behaviour. PLAY TONE works from the command line, but not at all from within a program. Should I suspect the SD card? I've already edited / saved / renamed my test programs many times, so, presumably, they have been stored in different SD card areas (?). It looks like CubeProgrammer may be able to do something like a memory check, but I'm already operating beyond my understanding, and I can't follow the Cube Programmer manual or instructions, and wouldn't understand the output anyway. I really shouldn't play with big boys' toys... |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Let's go back to basics The PLAY TONE command is non-blocking so it starts the tone and then immediately returns. As you observe the pause is triggered from the start - this is correct. If have a program Play tone 100,100 play tone 200,200 You will hear nothing. Each play command happens nearly instantaneously and then the program ends which turns off the sound. This is the case even if you specify a duration for the tone. The second play tone immediately replaces the first and the end of the program stops any sound. Try: play tone 100,100 pause 1000 play tone 200,200 pause 1000 Please try this and let us know what happens Edited 2021-08-10 18:46 by matherp |
||||
BitLost Newbie ![]() Joined: 07/08/2021 Location: New ZealandPosts: 15 |
Great! Thank you! So it was me, all along... As far as PLAY TONE goes, it seems to work. ![]() It seems that one has to be very careful about adding suitable PAUSEs, in addition to tone duration, so the command is effectively a PLAY TONE + PAUSE hybrid. I'll now play around a bit more, with PLAY SOUND, bearing this in mind, although I think I've done enough already to believe that square waves and sine waves may require different treatment (PAUSEs following sine wave, perhaps). See silly program in third post. In my defence, I don't think this is made clear in the manual. I can't be the only relative novice out there... |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2442 |
BitLost: you are playing into a stereo amplifier, with two speakers? peter: if playing stereo (ie, using PLAY SOUND n, B... are the two sound output pins guaranteed to always be simultaneously in exactly the same state? ie, not out of phase, one pin lagging behind the other a fraction, etc. the CMM2 has no internal isolating capacitors, so a mono 3.5mm plug will be shorting one channel directly to ground. if the two output pins happen to be producing a signal exactly 180 degrees out of phase, the two channels - if combined with series capacitors or series resistors into a single channel - will produce (next to) no output. cheers, rob :-) reference: https://www.c-com.com.au/mmhelp/play_sound.htm Edited 2021-08-10 23:58 by robert.rozee |
||||
BitLost Newbie ![]() Joined: 07/08/2021 Location: New ZealandPosts: 15 |
Glad to say that, thanks to Peter's explanation, I now understand. It all works! It seems that it's safest to follow a PLAY SOUND (or TONE) command, in which duration is specified, with a PAUSE x command, where x >= duration. A bit cumbersome, and at first sight unnecessary duplication, but I understand, and also understand that the PAUSE command can be dispensed with in some situations. Thanks for your patient help. One thing that confounded the issue is that I have been using a skip-rescue screen, with the most pathetic built-in speakers. It's now clear that these can't produce fundamental tones below a couple of hundred Hz, so a 200Hz sine wave is inaudible, but a 200Hz square wave is, thanks to its harmonic content! robert.rosee: Yes, all 2-channel. No problem with audio side (except pathetic speakers). Good point about lack of o/p caps. I'll make up an audio lead 'dongle' for safety. I'm too lazy to try to re-do the mother-board's audio o/p socket to incorporate caps, although that would be preferable... |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
TBH I've never really understood why the output couldn't have just been via a 470R resistor on each channel. It would protect against short circuits, not bother digital inputs (or many outputs), make no difference to audio (you could pop a potential divider on as well for a low level output), protect against all types of headphones and allow direct connection of an LED to each channel. :) I looked at modifying my CMM2 and there is space on the PCB where the resistors could have gone (and may still do but it means scratching away some track). Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |