Buzby
Senior Member
Looking for a low component method of making a sonar 'ping' for the subhunter, I thought this up.
The M2 chips have a Digital-to-Analog converter.
This can amplitude modulate a signal arriving on the +Vref pin.
By connecting a PWM output to the +Vref input the DAC can then modulate the PWM, with no extra components needed.
By adjusting the PWM 'on the fly' the tone can be changed as the amplitude varies, giving lots of possibilities.
The DAC output is very low current, but it can drive a piezo.
An amplifier ( LM386 or similar ) could be used to drive a speaker, but I wanted an ultra low component count.
It should be able to make lots of sounds this way, bird tweets, cat meows, etc.
Cheers,
Buzby
The M2 chips have a Digital-to-Analog converter.
This can amplitude modulate a signal arriving on the +Vref pin.
By connecting a PWM output to the +Vref input the DAC can then modulate the PWM, with no extra components needed.
By adjusting the PWM 'on the fly' the tone can be changed as the amplitude varies, giving lots of possibilities.
The DAC output is very low current, but it can drive a piezo.
An amplifier ( LM386 or similar ) could be used to drive a speaker, but I wanted an ultra low component count.
Code:
#picaxe 08M2
#no_data
' Sonar ping
' ----------
' Hardware wiring
'
' __ __
' | |_| |
' +v -| |- 0v
' | |
' -|C.5 C.0|->----------------------
' | | |
' -|C.4 C.1|-<- |
' | | | Link -| Piezo
' -|C.3 C.2|->- -|
' |_______| |
' |
'------------------------------------------------------ 0v
'
'
'
' C.0 is DAC output
' C.1 is Vref input
' C.2 is PWM output
'
Symbol Alev1 = b2 ' Amplitude level 1
Symbol Alev2 = b3 ' Amplitude level 2
Symbol Pduty = b4 ' PWM duty
setfreq m8 ' Run at 8MHz
dacsetup %10100100 ' Set DAC to use external +Vref, DAC out to C.0
do
Pduty = 100
pwmout pwmdiv16, 2, 199, Pduty ' Set PWM
daclevel 31
for Alev1 = 31 to 0 step -1 ' Make a descending amplitude envelope.
Alev2 = Alev1 * 9 / 10
daclevel Alev1
pause 20
Pduty = Pduty + 10 : pwmduty c.2, Pduty
daclevel Alev2
pause 20
Pduty = Pduty + 10 : pwmduty c.2, Pduty
daclevel Alev1
pause 20
Pduty = Pduty + 10 : pwmduty c.2, Pduty
daclevel Alev2
pause 20
Pduty = Pduty + 10 : pwmduty c.2, Pduty
daclevel Alev1
pause 20
Pduty = Pduty + 10 : pwmduty c.2, Pduty
daclevel Alev2
pause 20
next
pause 4000
loop
Cheers,
Buzby
Attachments
-
736.3 KB Views: 126