View Full Version : need help! to beginner
emilhs
- 20th April 2009, 23:25
Hello I want to write code to imitate siren sounds li Air horn pulsar wait yelp .
i have used freqout to make first 2. but others do not stop when i unpress button lease advise what to do?
If PORTB.7 =0 THEN
Freqout PORTB.0,4,1700 ;------------- air horn
Freqout PORTB.0,4,850
Freqout PORTB.0,4,1250
Freqout PORTB.0,4,425
Endif
If PORTB.6 =0 THEN
Freqout PORTB.0,8,366 ;------------- pulsar
Freqout PORTB.0,8,483
Freqout PORTB.0,8,591
Freqout PORTB.0,8,664
Freqout PORTB.0,8,760
Freqout PORTB.0,8,886
Freqout PORTB.0,8,967
Freqout PORTB.0,8,1070
Freqout PORTB.0,8,1182
Freqout PORTB.0,8,1330
endif
for this too freqout is ok because they are short what to do with longer ones?
mister_e
- 22nd April 2009, 16:14
Well, post your whole code, and schematic, we could help further.
emilhs
- 22nd April 2009, 16:44
TRISB = %11111111
OPTION_REG.7 = 0
loop:
If PORTB.7 =0 THEN
Freqout PORTB.0,4,1700 ;------------- air horn
Freqout PORTB.0,4,850
Freqout PORTB.0,4,1250
Freqout PORTB.0,4,425
Endif
If PORTB.6 = 0 Then
Freqout PORTB.0,8,366 ;------------- pulsar
Freqout PORTB.0,8,483 ;
Freqout PORTB.0,8,591
Freqout PORTB.0,8,664
Freqout PORTB.0,8,760
Freqout PORTB.0,8,886
Freqout PORTB.0,8,967
Freqout PORTB.0,8,1070
Freqout PORTB.0,8,1182
Freqout PORTB.0,8,1330
Endif
If PORTB.5 = 0 Then
Freqout PORTB.0,10,366 ;------------- yelp
Freqout PORTB.0,10,483
Freqout PORTB.0,10,591
Freqout PORTB.0,10,664
Freqout PORTB.0,10,760
Freqout PORTB.0,10,886
Freqout PORTB.0,10,967
Freqout PORTB.0,10,1070
Freqout PORTB.0,10,1182
Freqout PORTB.0,10,1330 ---------- how to check? just to say if in this point button is unpressed and stop running
Freqout PORTB.0,10,1182
Freqout PORTB.0,10,1070
Freqout PORTB.0,10,967
Freqout PORTB.0,10,886
Freqout PORTB.0,10,760
Freqout PORTB.0,10,664
Freqout PORTB.0,10,591
Freqout PORTB.0,10,483
Freqout PORTB.0,10,366
endif
goto loop
end
mister_e
- 22nd April 2009, 17:06
One of the several way to do it, untested though
Frequency var word
CounterA var Byte
If PORTB.5 = 0 Then
CounterA = 0
Yelp:
Lookup2 CounterA,[366,483,591,664,760,886,967,1070,1182,1330,1182,10 70,967,886,_
760,664,591,483,366],Frequency
Freqout PORTB.0,10,Frequency
if PORTB.5=0 then
CounterA = CounterA + 1
if Countera < 19 then goto Yelp
endif
endif
emilhs
- 22nd April 2009, 18:53
thank you wery much
emilhs
- 23rd April 2009, 20:50
Can anybody show different way of doing the same???
mister_e
- 23rd April 2009, 21:30
Well yes, but why? It doesn't work or what?
emilhs
- 23rd April 2009, 22:26
But if just to say I want to add pause i cannot.
I added a coulpe of 0 to get silence but it gives whistle.
so i need something with supporting pause command
thanks in advance
mister_e
- 24th April 2009, 08:54
where do you want to add pause? between some FREQOUT?
emilhs
- 24th April 2009, 09:06
yes I do. is it possible?
emilhs
- 24th April 2009, 09:19
Stieve is it possible to put as duration in sound command figure beetween 0-1
for examle
sound portb.0[0.2 ,115]
because when you put 1 sound comes out nearly 12 milliseconds but i need less
mister_e
- 24th April 2009, 09:20
Sure, easy way is to break the LOOKUP2 in few different tables, or add a second one, the second one will hold the PAUSE value.
I could disgress and say use a variant of "embedded string in your code space". This build a huge table in which you store, the frequency & the PAUSE values. Later you just read it, and apply it.
mister_e
- 24th April 2009, 09:25
PBP don't allow float point values.
You could use HPWM out and PAUSEUS/PAUSE, or a variant of it.
Some
High pin
PAUSE(us) HalfPeriodDelay
LOW pin
PAUSE(us) HalfPeriodDelay
would replace Sound, Freqout, PWM etc etc hapilly here
emilhs
- 24th April 2009, 09:32
Steve is there any way by any comant get figures like 0.2 point two point tree?
mister_e
- 24th April 2009, 21:30
Nope, not as far as I'm aware of.
emilhs
- 25th April 2009, 22:41
Hi steve.
how can i devide the table into two parts and put pause between them?
Emil
emilhs
- 26th April 2009, 22:09
Yelp3:
Lookup2 CounterA,[366,425,483,591,664,760,886,967,1070,1182,1330],Frequency
pause 10
lookup2 countera,[1330,1182,1070,967,886,760,664,591,483,425,366],Frequency
Freqout PORTB.0,16,Frequency
if PORTB.5=0 then
CounterA = CounterA + 1
if Countera < 22 then goto Yelp3
endif
emilhs
- 29th April 2009, 21:38
anybody can help?
mister_e
- 30th April 2009, 12:18
I would like to know all your delays and all your frequency, you could also build 2 lookup, one for the delays, one for the frequency.
emilhs
- 30th April 2009, 20:39
Is it wright that lookup can get only 85 figures?
if yes how can i write 3 lookup comands but i need like after one finishing it must count second and then third table. if button pressed.
Thanks in advance.
Emil
Dave
- 30th April 2009, 21:06
emilhs, The lookup command can have upto 255 results. I have used it with upto 128 in a lookup table for a serial/dotmatrix display system...
Dave Purola,
N8NTA
emilhs
- 30th April 2009, 23:29
Thanks Dave
emilhs
- 30th April 2009, 23:32
Steve can you please show me how to buld 2 lookups? and I will work it out
Emil
Dave
- 1st May 2009, 11:42
emilhs, I think he means something like this:
--------------------------------------------------------------------------------
Yelp3:
Lookup2 CounterA,366,425,483,591,664,760,886,967,1070,1182 ,1330,1330,1182_
1070,967,886,760,664,591,483,425,366],Frequency
Lookup2 CounterA,366,425,483,591,664,760,886,967,1070,1182 ,1330,1330,1182_
1070,967,886,760,664,591,483,425,366],Delay
Then use the "Frequency" and the "Delay" variables together to make a sound (multiple ways) then do it again,
Yelp4:
Lookup2 CounterA,366,425,483,591,664,760,886,967,1070,1182 ,1330,1330,1182_
1070,967,886,760,664,591,483,425,366],Frequency
Lookup2 CounterA,366,425,483,591,664,760,886,967,1070,1182 ,1330,1330,1182_
1070,967,886,760,664,591,483,425,366],Delay
Dave Purola,
N8NTA
emilhs
- 1st May 2009, 15:17
but i need function like when the button is unpressed counting stops
Dave
- 1st May 2009, 16:40
emilhs, Just place a test for the appropriate input bit between calls to the lookup table...
Dave Purola,
N8NTA
emilhs
- 1st May 2009, 18:51
Thanks Dave i will try and let you know
emilhs
- 6th May 2009, 18:44
PBP don't allow float point values.
You could use HPWM out and PAUSEUS/PAUSE, or a variant of it.
Some
High pin
PAUSE(us) HalfPeriodDelay
LOW pin
PAUSE(us) HalfPeriodDelay
would replace Sound, Freqout, PWM etc etc hapilly here
Hi Steve,
This is the best way I try but again I got problem and now i can not calculate the perods for Frequencies can you help me please ?
is there any formula or software for it?
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.