Help required to create a dual tone

jay4708

New Member
Hi

Can someone please give me a little help creating a dual tone with the following characteristics:-

A 'Period' of 1ms for 0.5 seconds (0.5hz) and then a 'Period' of 2ms for 0.5 seconds (0.5hz), then repeat until stopped​

I've spent all day playing and trying to learn PWM on the picaxe, I've had a couple of results but I'm not getting it, not even sure that is the right way to do it.

Thanks for your help in advance.

John
 

srnet

Senior Member
Did you try the PWMOUT Wizard in the editor ?

You tell it the clock speed of the processor, the pin you want the output on, the frequency you want, set the duty cycle to 50% for a tone, and it will give you the command to use.
 

jay4708

New Member
Hi,

I did have a play with the PWMOUT Wizard.

How would I control the 'Period' as I need 1ms tone and then a 2ms tone?

Thanks
 

AllyCat

Senior Member
Hi.

A "tone" with a period of 1 ms has a frequency of 1 kHz, one with a period of 2 ms has a frequency of 500 Hz. So just use a PWMOUT command for a frequency of 1000 Hz and a duty cycle of 50% (or you might try other ratios as a pseudo-volume control) and then PAUSE for 500 ms. Then a PWMOUT for 500 Hz and the same duty cycle, another PAUSE 500 and loop back to repeat as required.

You hardly need the Wizard because the "raw" PICaxe command defines the PWM frequency in terms of the total period and the duty cycle (on-time). But the Wizrd may help with the necessary multiplication/division parameters (e.g. you'll probably need to use a PWMOUT PWMDIVn,.....).

Cheer, Alan.
 

jay4708

New Member
Thanks Alan, I've done it:-

main:
pwmout pwmdiv4, C.2, 249, 499
pause 500
pwmout pwmdiv16, C.2, 124, 249
pause 500
goto main

Thanks for your help
 

jay4708

New Member
Hi again,

The above bit of code produces the tone I require but it starts straight away, how can I call it up when I need it and then stop it?

Thanks
 

westaust55

Moderator
Using a pin as an input, you can use a resistor to pull the pin low and a switch to the supply voltage to indicate when to start.

Then using and IF ... THEN ... ENDIF structure

iF pin< port.pin> = 1 THEN ; for example pinC.5
<do tone routine>
ENDIF

If you want to depart the tones continuously until another switch puls then add a further IF... THEN to return to start of you tones until another switch puls detected.

Using interrupts and setting a flag for testing when to start or stop could be better as the flag can be set between commands rather than wait until end and miss turning off signal.
 

AllyCat

Senior Member
Hi,

It depends how you want to control the tone. It might be by one or more push-button switches, an Infra Red or Radio Remote Control link, "Serial" commands from the PICaxe terminal (SERRXD) or some type of direct program control.

Basically, your "main" program should decide what needs to be done and then jump to your present code (which sholuld now be given a more meaningful label name) when the tone is required to start. A clue to ending the tone is at the end of my first paragraph in #4 above: "...loop back to repeat as required."

In practice you may have complications with "blocking" commands (which prevent other parts of the program running), so you may need to adopt multitasking (multiple start: labels), an interrupt, or perhaps a larger "polling" loop (replacing the PAUSEs).

Cheers, Alan.
 
Top