Struggling again with SEROUT2 and numbers format


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    for one
    your volup: subroutine
    has a goto main in it , this will eat up the stack , pic18 subs can only nest 22 levels deep at the most
    subroutines aren't re-entrant and must return to where they called from .

    VOLUP: ' All variables are set as bytes
    '
    Z = $01 ' For future functions
    DO
    IF Leader > DL1 THEN
    GOSUB VOLUP1 ' Go to increase volume
    ELSE
    pattern = 0
    GOSUB Out_595
    GOTO MAIN
    ENDIF
    PULSIN INFRA,0,Leader ' Check again for start pulse (autorepeat function) WORKS
    LOOP
    GOTO VOLUP ' Go back to main routine to check for another button press
    '
    '================================================= =================================================
    '================================ VOLUME INCREASE AND BYTE CALCULATIONS =======================
    '================================================= =================================================
    '
    VOLUP1:

  2. #2
    Join Date
    Oct 2012
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    Quote Originally Posted by richard View Post
    for one
    your volup: subroutine
    has a goto main in it , this will eat up the stack , pic18 subs can only nest 22 levels deep at the most
    subroutines aren't re-entrant and must return to where they called from .

    VOLUP: ' All variables are set as bytes
    '
    Z = $01 ' For future functions
    DO
    IF Leader > DL1 THEN
    GOSUB VOLUP1 ' Go to increase volume
    ELSE
    pattern = 0
    GOSUB Out_595
    GOTO MAIN
    ENDIF
    PULSIN INFRA,0,Leader ' Check again for start pulse (autorepeat function) WORKS
    LOOP
    GOTO VOLUP ' Go back to main routine to check for another button press
    '
    '================================================= =================================================
    '================================ VOLUME INCREASE AND BYTE CALCULATIONS =======================
    '================================================= =================================================
    '
    VOLUP1:

    OMG !!!
    Thank you Richard, I couldn't see the obvious !!!
    I feel I have to post the solution you provided and I ended up with a smaller code that does the same.

    Code:
    '==================================================================================================
    '===================================   VOLUME UP SUBROUTINE    ====================================
    '==================================================================================================
    '
    VOLUP:                                           '
    '
    Z = $01                                          ' Volume sub command
    DO WHILE Leader > DL1                            ' If START pulse increase volume
        GOSUB VOLUP1                              
        PULSIN INFRA,0,Leader                        ' Check for another for auto repeat
    LOOP
    pattern = 0                                      ' LED OFF
    GOSUB out_595
    RETURN                                           ' Go Back to Commands and then Main
    '
    Now I have to fight with the PULSIN command @ 16 MHz.
    If someone asks why to go @ 16 MHz if 4 Mhz works OK, the answer is that I need higher serial port speeds.

    @ 4 MHz I use DL1 = 800 and DL2 = 110

    so @ 16 MHz I have to use DL1 = 3200 and DL2 = 440.

    but the above values are not working. I'm sure I'm missing something, I wonder what is it :-)

    I don't think is a hardware problem, the HX1838 infrared receiver is connected to PORTD.7 and a pullup resistor of 10K is also used.
    I tried also without the pullup and the results are the same and tried to move ports but no luck.

    Thanx
    Fanias

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    That would do it 'cause I use that PIC at highest internal osc setting and it works great.

    VOLUP should exit with a RETURN. Also, READ32 should not have a GOTO MAIN in it as well.

    Robert

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    from the manual :-
    The resolution of PULSIN is dependent upon the oscillator frequency. If a 4MHz oscillator is used, the pulse width is returned in 10us increments. If a 20MHz oscillator is used, the pulse width will have a 2us resolution. Defining an OSC value has no effect on PULSIN. The resolution always changes with the actual oscillator speed.

    more info
    @16 MHz that's 2.5uS units
    8.5mS =3400 ,1.5mS =600
    Last edited by richard; - 11th April 2014 at 13:12.

  5. #5
    Join Date
    Oct 2012
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    Quote Originally Posted by richard View Post
    from the manual :-
    The resolution of PULSIN is dependent upon the oscillator frequency. If a 4MHz oscillator is used, the pulse width is returned in 10us increments. If a 20MHz oscillator is used, the pulse width will have a 2us resolution. Defining an OSC value has no effect on PULSIN. The resolution always changes with the actual oscillator speed.

    more info
    @16 MHz that's 2.5uS units
    8.5mS =3400 ,1.5mS =600
    Thank you both for your usefull comments.

    @ Richard,

    you are correct, I've done my self calculations and we are the same.
    The problem must be somewhere else or at PIC configuration (maybe ??)

    Since I don't have any other way to see what happens here, I'm simply printing on LCD the values I'm reading with the PULSIN command.
    My results are correct @4 MHz but wrong at 16 MHz.

    @4 MHz I get for "Start" pulse, "0" pulse and "1" pulse respectively : 898, 56, 168. These results are correct according to the NEC protocol (for ex. 898 * 10 us ~ 9 ms which is fine for the start pulse).

    But @ 16 MHz I get : 3600, 229, 129.

    The 3600 result is correct (~ 898 * 4),
    The 229 result is also correct (~ 56 * 4),
    BUT 128 is wrong and should be ~ 168 * 4 = 672 !!!

    So here is my problem, I can read @16 MHz the "Start" pulse and "0" pulse, but the "1" pulse is wrong, it's way LOWER value than it should be.

    What do you think about this ?

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    does it really matter why not call it a "0" if < 180 or a "1" if > than 180
    what are you using for ir receiver , could it be noise or the "carrier wave" slipping through
    how good is your power supply ,is everything bypass capped properly ?

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    Hi,
    I'm not sure which is what here but I see only one WORD variable (Leader) being declared. If you expect PULSIN to return a value >255 then make sure to give it a WORD variable to store that result in.

    /Henrik.

Similar Threads

  1. Still Struggling with the formula!
    By Ramius in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 10th April 2012, 06:58
  2. Struggling Newbie
    By plakey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th March 2012, 14:05
  3. Struggling with a P18f2550
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th November 2011, 07:58
  4. Still Struggling with IF THEN
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 25th March 2007, 10:47

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