Question (possibly dumb!) about sound

I have briefly tried experimenting with the sound command, as an experiment I tried using 2 pins on the 08m2 hoping to get a sound at the same time from both pins, but what is happening is that one sounds then the other, is there a way to do what I want or am I expecting miracles? :eek:
 

inglewoodpete

Senior Member
I have briefly tried experimenting with the sound command, as an experiment I tried using 2 pins on the 08m2 hoping to get a sound at the same time from both pins, but what is happening is that one sounds then the other, is there a way to do what I want or am I expecting miracles? :eek:
Yes, you're expecting miracles.:eek:

Having said that, you can get (sort of) polyphonic sounds out of most of the chips (other than the 08M2). This can be done by using two or more PWM pins and setting them to different frequencies/duties on the fly.
 
Last edited:
Here is the code (epic huh?)
init:
SETFREQ m8
main:
sound c.1,(48,10) sound c.2,(65,20)
goto main
Maybe I am misunderstanding the multi tasking abilities of the 08M2, I thought that it would be able to do upto 4 things at once from what I read when looking into it, ha!
 

inglewoodpete

Senior Member
...up to 4 things at once...?
Unfortunately, the current range of PICAXEs are single core chips so that some of them can run 4 processes at once but can only do once thing at a time. I don't think the documentation says "4 things at once".

Unless you get special hardware functions to run concurrently, like the PWM I mentioned in an earlier post.
 

Goeytex

Senior Member
A Picaxe cannot not do real multitasking. Picaxe 'multitasking' is accomplished by switching (alternating) between tasks while attempting to equally divide the time between tasks. But still, only one command be executed at a time. I think this is explained in the manuals somewhere. At least it should be.
 
Yeah my general lack of understanding of the meaning is what caught me out, and if I'm being honest I kind of doubted that it could do it.

So lets say I just want a few pins to go high at the same time, that can be done right? (forget about the sound function)
 

inglewoodpete

Senior Member
Yes. Refer to the 'High' (or 'Low') command in the command manual.

If you can arrange your outputs on the same port, then use commands like OutPinsA = %1010100
 
Thanks, forgive my ignorance, I have seen the %1010100 referred to before, how do the 1's and 0's relate to the actual hardware pins?
 

eclectic

Moderator
Have a play with this as a starter.

Code:
#picaxe 08M2 

dirsC = %00010111  ;Pin 0 is ouput only 

Let pinsC= %00010111  ; note Pin3 is an input only 

pause 1000 

Let pinsC= %00010101 

pause 1000
; and so on
 

Goeytex

Senior Member
It seems that it does not apply to the 08m2 though?
It seems that it does.

Manual 2 is a bit confusing where the 08M2 is shown on Page 14 and "OUTPINS" is not mentioned. The manual seems to suggest that for the 08M2 it should be PINS = OUTPINS is only mentioned in regards to the other M2 chips on page 15. However in practice outpinsC seems to work fine on the 08M2. I have found that when in doubt, try it. The best way to learn Picaxe BASIC is to write the code and run it in the simulator and then test it on a chip. If there is a syntax error or an unsupported command the Program Editor will let you know.

Consider the code below. All four routines work fine on an 08M2. How do I know? ....... I tried them.

Code:
#picaxe 08M2
#no_data
	
symbol cnt = b0        '// counter variable  
dirsC = %00010110     '// set pins c.1, c.2, & C.4 as outputs

MAIN:	
	
	'// Try outpinsC
	for cnt = 1 TO 10 
	   outpinsC = %00000000    '// Toggle the pins ever 100ms 
	   pause 100
	   outpinsC = %00010110
	   pause 100
	next   
		  
	'// Try "pins"
	for cnt = 1 to 10  
	   pins = %00000000    '// Toggle the pins every 100ms 
	   pause 100
	   pins = %00010110
	   pause 100
	next 
	
	'// Try "PinsC"
	for cnt = 1 to 10
	  pinsC = %00000000    '// Toggle the pins every 100ms 
	  pause 100
	  pinsC = %00010110
	  pause 100
	next
	
	'// Try "PinsB"
	for cnt = 1 to 10
	  pinsB = %00000000    '// Toggle the pins every 100ms 
	  pause 100
	  pinsB = %00010110
	  pause 100
	next
	
GOTO MAIN
 

srnet

Senior Member
It seems that it does not apply to the 08m2 though?
Sorry, I thought you did ask for an explanation of how the %0100010 bit relates to specific output pins.

The way its done (as per the bit of manual I pointed to) is common to a fair few commands.
 
Well I was, but as per my first post I mentioned I was using a 08m2, and I had seen that reference though could not remember where, then when I looked again in the manual it seemed to imply that it did not apply to the 08m2, ha! Also from what I can make out the first two digits are irrelevant for the 08m2, is that right? IE that %00110111 and %110111 are essentially going to give the same result, because there are only 6 useable pins.

Anyway, thanks for the help guys!
 
Top