PDA

View Full Version : how building sound tone and runing other instructions in background



ustredna
- 1st November 2005, 19:12
please help me,


How building sound tone and runing other instructions in background

tone duration cca. 5 sec.
and other program are runing.
mcu type is 16F84A and xtal is 4Mhz.

all help in my email:

tnx.
Peter / ustredna

asifiqbal
- 14th January 2016, 18:45
i have same question any answer ?

towlerg
- 14th January 2016, 18:54
use a timer interupt.

asifiqbal
- 14th January 2016, 19:10
here is my code for pic16f72 ,i want to generate a beep for 2 sec without pause inside the inverter loop when program shift from acmode: to inverter: mode or inverter to acmode ,i used sound command but it gives pause of 2 sec,i m using piezo buzzer driven by bc 547 ,hpwm pin is also free any sugestion?

INVERTER:

;---------------------
b1=1
pauseus x
b1=0
pauseus y
;------------------------
adcin 1,ct
adcin 2,batt

if ct > 127 then loadtrip
if batt < 50 then lowbatttrip


if batt >127 then
LED20=1:led40 =1:led60=1:led80=1:led100=1
endif
if batt < 127 and batt>120 then
led20=1:led40 =1:led60=1:led80=1:led100=0
endif

if batt < 120 and batt>110 then
led20=1:led40 =1:led60=1:led80=0:led100=0
endif
if batt < 50 then
led20=1:led40 =1:led60=0:led80=0:led100=0
endif
'------------------------
b2=1
pauseus x
b2=0
pauseus y
;---------------------------

adcin 0,ac
adcin 3,fixvolt

if fixvolt > 127 then
z=z+10
endif
if fixvolt < 127 then
z=z-10
endif

while z>9000
z=9000
wend
while z<1000
z=1000
wend
x=9000-z
y=1000+z
if ac > 127 then acmode
If SW = 0 Then SWITCH
'----------------
goto inverter

Amoque
- 15th January 2016, 12:23
I think there are several methods you ay use.

You could have an interrupt routine that beeps for a short time, repeatedly. In the interrupt set a flag that increments with each very short beep until it has been on long enough then, disable the interrupt. Pseudo code:


INTERRUPT:

Flag = flag + 1
Make short beep
if flag = 100 then flag = 0 and turn off interrupt

Main:
If error then turn on interrupt
code
code
goto Main

Or, as an alternative, you could make or buy a buzzer module. When you need noise, turn it on with a single pin, when you don't - turn it off same way.

Or, as you suggest your PWM pin is free, wire up the buzzer there. As PWM runs independently of code...