need help! to beginner


Closed Thread
Results 1 to 28 of 28
  1. #1
    Join Date
    Apr 2009
    Posts
    29

    Unhappy need help! to beginner

    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?

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Well, post your whole code, and schematic, we could help further.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default I can not stop running of programm when on some point the button is unpressed

    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
    Attached Images Attached Images  

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    One of the several way to do it, untested though
    Code:
    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,1070,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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Thumbs up I will try it

    thank you wery much

  6. #6
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default More info needed

    Can anybody show different way of doing the same???

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Well yes, but why? It doesn't work or what?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default no it does

    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

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    where do you want to add pause? between some FREQOUT?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default exactly

    yes I do. is it possible?

  11. #11
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default sound command

    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

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default figures

    Steve is there any way by any comant get figures like 0.2 point two point tree?

  15. #15
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Nope, not as far as I'm aware of.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  16. #16
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default two lookup2 commands

    Hi steve.
    how can i devide the table into two parts and put pause between them?

    Emil

  17. #17
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default will it work?

    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

  18. #18
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default anybody can help?

    anybody can help?

  19. #19
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  20. #20
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default 2 lookup or 3 lookup

    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

  21. #21
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    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

  22. #22
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks Dave

  23. #23
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default 2 lookup

    Steve can you please show me how to buld 2 lookups? and I will work it out

    Emil

  24. #24
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    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

  25. #25
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default May be

    but i need function like when the button is unpressed counting stops

  26. #26
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    emilhs, Just place a test for the appropriate input bit between calls to the lookup table...

    Dave Purola,
    N8NTA

  27. #27
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default let's see

    Thanks Dave i will try and let you know

  28. #28
    Join Date
    Apr 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default frequency

    Quote Originally Posted by mister_e View Post
    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?

Similar Threads

  1. Replies: 17
    Last Post: - 12th April 2014, 02:17
  2. pic24 beginner
    By robertpeach in forum General
    Replies: 23
    Last Post: - 13th August 2009, 11:57
  3. Replies: 10
    Last Post: - 2nd May 2009, 07:42
  4. Beginner trying to use arrays
    By captain in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 3rd November 2007, 07:20
  5. Pic ID Error please help (beginner)
    By ninja in forum General
    Replies: 4
    Last Post: - 11th August 2005, 17:54

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts