model sound

piclt

Member
There are loads of boat engines and horns...... post some code so we can see how far you have got or a recording of a sound you want.
 

piclt

Member
Code can do anything, you need to say what you think you need and read the sections in manual or examples and post your trial code.
basic pwm code is pwmout, pin, period, duty
eg ..... pwmout B.3, 200, 400 is a square wave out on B.3
Are you wanting PWM to play a simulation of an analog audio signal by varying duty or do you want pwm to generate a simple tone.
 

piclt

Member
How are you playing the sounds, do you want picaxe to do everything or is picaxe just controlling a player..?
Picaxe can just play pwn square waves, sounds, tones, tunes etc and there are wizards for working with them in the editor. You need to try them and post problems
There are examples in the manuals and in the editor as well
 

papaof2

Senior Member
Where has the time gone indeed?
I built a temperature controlled fan for the A/V cabinet - using an 08M - in September 2006. Other than replacing the fan multiple times, it's still running just fine (I have a new-in-the-box fan waiting for the next failure ;-). When the temperature at the hottest point in the cabinet rises to 86F/30C, the fan turns on and runs until the temperature drops to 82.4F/28C. The LED in the translucent box (small plastic container that some hardware came in) is on while the DS18B20 is being read and then flashes twice if the temperature is above the lower limit (could be rising or falling).
The PICAXE chips are reliable little slaves if you stay within their limits - the fan is controlled by a 2N4401 transistor that's driven by a pin on the PICAXE through a 4K7 resistor.

My code was adapted from an example published by Peter H Anderson. It shows how to avoid working with negative numbers when measuring temperature with a DS18B20.

Code:
' AV-Fan.bas
' control A/V cabinet cooling fan based on temperature reported by DS18B20
'
' Adapted from DS18B20_08M_3.Bas - PICAXE-08M
'
' Illustrates an interface with the DS18B20 in monitoring temperature.  An alarm
' is associated with the temperature.
'
' If the temperature measured on the DS18B20 associated with IN1 is abve HighTrip, a relay
' on Out4 (term 3) is operated.  It is released when the temperature falls below LowTrip
'
' Note that HighTrip and LowTrip are specified as the temperature plus 60 degrees C to avoid
' working with negative numbers.
'
' Note that a 4.7K pullup to +5 VDC is required on the DQ lead.  +5 VDC is required on the
' V+ terminal of the DS18B20.
'
'  08M                    DS18B20
'
' IO1 (term 7) ------------------ DQ (term 2)
'
'                            2N4401 ---(FAN)-- +
'                                 |/
' OUT4 (term 3) ------- 4K7 ----->|\
'                                   -- GRD
'
' Uses 68 of 2048 bytes (08M2) - or 65 of 256 bytes.(08M)
'
' original DS18B20 code copyright, Peter H Anderson, Baltimore, MD, Sept, '04
' AV-Fan changes copyright John E Carter 24 Sept 2006

    symbol counter = b1
    Symbol TempC_100 = W3
    Symbol DevNum = W6
    Symbol Temp_8 = B9

    'need 100 as HighTrip and 98 as LowTrip for Traces 3210A solar controller external fan
    Symbol HighTrip = 98    '(100.4F)    ' 38 + 60 - fan on when temp hits 100F - adjust as necessary
    Symbol LowTrip = 96       '(96.8F)    ' 36 + 60 - fan off when 2 deg cooler

    low 0        'set unused pin

    high 4    'operation verification on power up (fan on)
    high 2    '(status LED on)
    pause 600
    low 2
    Low 4    ' turn off alarm
Top:
    high 2            'indicate a read is in progress (power/activity light)
      ReadTemp 1, Temp_8        ' read the high 8 bits - approx temp in deg C
    low 2



    ' respond to the temperature
    Temp_8 = Temp_8 + 60    ' to avoid negative numbers
    If Temp_8 >= HighTrip Then OperateAlarm
    if Temp_8 < LowTrip then continue
    'indicate if above LowTrip but below HighTrip
    for counter = 1 to 2
        pause 200
        high 2
        pause 200
        low 2
    next counter

continue:
    If Temp_8 < LowTrip Then ReleaseAlarm
    ' else
    Goto SequenceDone

OperateAlarm:
    High 4
    Goto SequenceDone

ReleaseAlarm:
    Low 4
    Goto SequenceDone

SequenceDone:
    Pause 1000    'was 20000
    GoTo Top
If I were to rewrite it today, it would get more use of "symbol" so the "high 2" would be "high LED" and similar changes. After 17 years that's just window dressing because the code works reliably. I'm from a generation that learned to write code in languages where the only informative things in that code were the comments - if the original programmer even bothered to put in comments :-( I did enough fixing of other people's code to get in the habit of having enough notes in what I wrote that I would know what the code was supposed to be doing when/if I had to make changes.

How reliably? Using the calculator at https://www.timeanddate.com/date/durationresult.html, as the day this was posted the PICAXE circuit has been running 17 years, 5 months, 21 days or 6383 days or 153,192 hours. Be nice if fans with an expected life (MTBF) of over 150,000 hours weren't priced so only the military can afford them :-(
 
Last edited:

piclt

Member
Don't work. :confused:
The thingy does work...... DAC on Picaxe is not like DAC on any other MCU. It is basically a digital pot with 32 steps allowing volume control of the Vref voltage. The thingy sets the daclevel steps and at same time plays in pwm in C.1.....so It mixes them and outputs on the DAC pin which is also the Serial out pin....... Don't keep serial OUT plugged in at same time as it will load the DAC output and you will get very low signal out. Manual says you should buffer it, but at least put it through an amplifier....... for quick test I plugged it into linein on PC and watched it and listened to it in Audacity. Here is another wee example.....

Code:
#picaxe 08M2
pwmout pwmdiv64, 2, 200, 400

;dacsetup %10100000 ; external DAC to C.0, Vref = supply voltage
dacsetup %10100100 ; external DAC to C.0, Vref link into C.1
setfreq m32

main:
gosub stepp
gosub upp
gosub downn
    goto main

upp:
for b0 = 1 to 31 step 1
    daclevel b0
    pause 100
   next
daclevel 30
pause 2000
return

downn:
for b0 = 31 to 1 step -1
    daclevel b0
    pause 200
   next
pause 5000
return

stepp:
for b0 = 0 to 10 step 1
daclevel 5
pause 100
daclevel 15
pause 100
daclevel 25
pause 100
daclevel 15
next
pause 1000
return
goto main
 
Top