Struggling again with SEROUT2 and numbers format


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Oct 2012
    Posts
    15

    Default Struggling again with SEROUT2 and numbers format

    Hello all,
    I think I need your help to resolve this.

    I have a radio that accepts commands via its serial port.
    My project is to remote control it (wireless or infrared) to change memories, volume, etc...

    Until now everything is OK so I'm posting only the program part I have stucked.
    With the following subroutine I want to increase the volume.

    So, first I want to read the current volume setting and then add 10 to increase the volume by ten units.
    But the radio is not accepting that command (and only that command).

    I think the problem is with the number format of the variables i use.
    As you can see from the code, the volume (and most other radio settings) has values from 0 - 254.
    For some unknown to me reason, the radio uses 2 bytes for theses values and not one.
    So, first byte gets values from 0 - 2 and second byte gets values from 0-99.

    To display them correctly to my serial LCD i use the HEX modifier and the appear OK as I manualy (not remotely) change the volume.

    At the end of the program I have entered some commands (for testing) to change the volume and they work fine !
    But when I place the variables in the SEROUT2 command nothing happens and the volume remains at the same level.

    What am I doing wrong ? Do you see something that needs to be changed for this thing to work ?

    Code:
    '################################################################################################################################
    ' VOLUME UP SUBROUTINE
    '
    VOLUP:                                                      ' All variables are set as bytes
    '
    '--------------------------------------------------------------------------------------------------------------------------------
    ' Volume in range 000 - 254
    ' f1 values are 00,01,02
    ' f2 values are 00 - 99  
    '--------------------------------------------------------------------------------------------------------------------------------                                              
    SEROUT2 CIVP,CIVS,[$FE,$FE,CIVA,$E0,$14,$01,$FD]            ' Send this to the radio to read Audio SETTING - WORKS !!!
    SERIN2 CIVP,CIVS,[SKIP 6,f1,f2]                             ' Skip first 6 useless bytes and read next 2 volume bytes  - WORKS !!! 
    '--------------------------------------------------------------------------------------------------------------------------------
    ' The next 4 lines are only for testing and to display a total volume value (000-254) to LCD in decimal
    '--------------------------------------------------------------------------------------------------------------------------------
    x1 = f1 & %00001111                                         ' read units - WORKS !!!
    x2 = f2 >> 4                                                ' divide / 2^4 = 16 (tens) - WORKS !!!
    x3 = f2 & %00001111                                         ' read units - WORKS !!!
    Z = x1 * 100 + x2 * 10 + x3                                 ' a number between 0 - 254                              
    '--------------------------------------------------------------------------------------------------------------------------------
    f3 = f1                                                     ' Same value for testing purposes only
    f4 = f2 + 10                                                ' Increase volume by 10 units - This is what I want to do
    pause 50                                                    ' Give some time to radio to recover from SERIN2
    SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,$f3,$f4,$FD]   ' Send this to the radio for NEW VOLUME setting - NOT WORKING :(
    'SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,f3,f4,$FD]      ' Send this to the radio for NEW VOLUME setting (no $) - NOT WORKING :(
    '--------------------------------------------------------------------------------------------------------------------------------
    serout2 lcdp,lcds,[i,line1," DEC : ", DEC3 Z,"-",DEC2 f3, DEC2 f4] ' Just print to serial LCD for debugging - It's correct + 10
    serout2 lcdp,lcds,[i,line2," HEX : ", DEC3 Z,"-",HEX2 f1, HEX2 f2] ' Just print to serial LCD for debugging - It's correct
    pause 50                                                    ' Give some time to radio to recover from SEROUT2
    '--------------------------------------------------------------------------------------------------------------------------------
    ' The following 3 lines are only for testing purposes - they all work OK !!!!!!!!!!!!
    '--------------------------------------------------------------------------------------------------------------------------------
    SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,$00,$00,$FD]      ' Mute, no sound, Z = 0 - WORKS OK !!!
    SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,$01,$28,$FD]      ' 50% volume, Z = 128 - WORKS OK !!!
    SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,$02,$54,$FD]      ' 100% volume, Z = 254 - WORKS OK !!!
    SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,$00,$00,$FD]      ' Mute again - my ears !!! - WORKS OK !!!
    '--------------------------------------------------------------------------------------------------------------------------------
    RETURN                                                      ' Go back to main routine to check for another button press
    '
    '################################################################################################################################
    Thanx in advance
    Fanias

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    Hi Fanias,
    Just a guess on my part
    SEROUT2 CIVP,CIVS,[$FE,$FE,CIVA,$E0,$14,$01,$FD] ' Send this to the radio to read Audio SETTING - WORKS !!!

    CIVA is uppercase

    SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,$f3,$f4,$FD] ' Send this to the radio for NEW VOLUME setting - NOT WORKING

    civa is lowercase

    I am GUESSING, since I do not know what the radio does but uppercase and lowercase letters are different numbers as all characters are numbers . . .
    also same for F vs f
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    Hi,
    Nah, I don't think that's it...
    CIVA must be a variable and they are not case sensitive. Had it been a string it should have been "CIVA" vs "civa"

    As a test, ditch the calculations and try:
    Code:
    f3 = $01
    f4 = $28
    SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,f3,f4,$FD]      ' Send this to the radio for NEW VOLUME setting (no $)
    In this particular case you do not want the $-sign because then it'll send the hexadecimal numbers F3 and F4 and not the content of the variables f3 and f4. Having the $-sign in there would have made the above statement send 243 ($f3), 244 ($f4) instead of 1 ($01), 40 ($28).

    /Henrik.

  4. #4
    Join Date
    Oct 2012
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Re: Struggling again with SEROUT2 and numbers format

    Thank you both for your time and answers.

    I think I found a solution, not sure why is this happening but works...

    I tread the numbers I read from radio as BCD, I convert them to binary, increase the volume by adding 10, convert them to BCD again and finally send them to the radio.

    I'm sure there must be an easier way to do this, because I can send other settings very easy.
    The civa is just a constant (address of the radio) and is civa = $70, the same as CIVA = $70.

    Here is the working code for your information, maybe you can help me to make it simpler without all these calculations.

    Code:
    VOLUP1:
    '
    '--------------------------------------------------------------------------------------------------------------------------------
    ' Volume in range 000 - 254
    ' f1 values are 00,01,02
    ' f2 values are 00 - 99  
    '--------------------------------------------------------------------------------------------------------------------------------                                              
    SEROUT2 CIVP,CIVS,[$FE,$FE,CIVA,$E0,$14,$01,$FD]            ' Send this to the radio to read Audio SETTING - WORKS !!!
    SERIN2 CIVP,CIVS,[SKIP 6,f1,f2]                             ' Skip first 6 useless bytes and read next 2 volume bytes  - WORKS !!! 
    '--------------------------------------------------------------------------------------------------------------------------------
    ' The next 4 lines are only for testing and to display a total volume value (000-254) to LCD in decimal
    '--------------------------------------------------------------------------------------------------------------------------------
    x1 = f1 & 001111                                         ' read units - WORKS !!!
    x2 = f2 >> 4                                                ' divide / 2^4 = 16 (tens) - WORKS !!!
    x3 = f2 & 001111                                         ' read units - WORKS !!!
    Z = x1 * 100 + x2 * 10 + x3                                 ' a number between 0 - 254                              
    '--------------------------------------------------------------------------------------------------------------------------------
    
    f3 = ((f1 >> 4) * 10) + (f1 & $0f)                          ' Convert BCD to binary
    f4 = ((f2 >> 4) * 10) + (f2 & $0f)                          ' Convert BCD to binary
    
    f4 = f4 + 10                                                ' Increase volume by 10 units - This is what I want to do
    IF f4 > 99 THEN 
        f4 = 0                                                  ' Make sure result is less than 100
        f3 = f3 + 1
    ENDIF
    IF f3 > 1 AND f4 > 54 THEN                                  ' If volume > 254 go back to volume 0
        f3 = 0
        f4 = 0
    ENDIF
    f5 = ((f3 / 10) << 4) + (f3 // 10)                          ' Convert bin to BCD
    f6 = ((f4 / 10) << 4) + (f4 // 10)                          ' Convert bin to BCD
    pause 50                                                    ' Give some time to radio to recover from SERIN2
    SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,f5,f6,$FD]      ' Send this to the radio for NEW VOLUME setting - THIS WORKS NOW :)
    pause 50                                                    ' Give some time to radio to recover from SEROUT2
    RETURN
    '--------------------------------------------------------------------------------------------------------------------------------
    Thanx again
    Fanias

  5. #5
    Join Date
    Oct 2012
    Posts
    15


    Did you find this post helpful? Yes | No

    Red face Now PIC hangs after 14 times of a subroutine execution

    Hello again,

    after solving my problems with serial port, I found that PIC (18F46K22) hangs after I send a command 14 times exactly.
    I'm using some code I found in the forum to remote control via the NEC infrared protocol a receiver.
    It works but when I press quickly 14 times the Volume UP button (to increase volume) the PIC hangs and a reset is needed.

    Three questions for anyone who wants to help.
    • I can't increase the Oscillator speed (e.x. το 16 MHz) to get the higher serial port speeds I need, the code works only at 4 MHz.
      I realize that the values of DL1 and DL2 must be icreased, but they don't work for DL1 = 3200 and DL2 = 440 (for 16 MHz), so I'm stuck to 4 MHz
    • The program hangs PIC when I call quickly 14 times the VOLUP subroutine. What is wrong in this subroutine ? I have also implemented a basic repeat function (VOL+ button always pressed which works)
    • How can I enable a feature or a function like WDT to avoid this hang when it occurs ? As you can see in the top of the program I tried to enable the WDT and tried different prescale values but nothing happens. Can you help with that in case I cannot fix the hang ?

    Here is the complete program :

    Code:
    '==================================================================================================
    '====================================   CONFIGURE PIC   ===========================================
    '==================================================================================================
    '                                                     # 18F46K22 #
    DEFINE OSC 4
    '
    DEFINE PULSIN_MAX 10000
    '
    @ CONFIG PBADEN = OFF                       ' PORTB<5:0> pins are configured as digital I/O on Reset
    @ CONFIG LVP = OFF                          ' Single-Supply ICSP disabled
    @ CONFIG XINST = OFF                        ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    '
    '@ CONFIG STVREN = ON                        ' Stack full/underflow will cause Reset
    '
    '@ CONFIG WDTEN = ON                         ' WDT is always enabled. SWDTEN bit has no effect
    '@ CONFIG WDTPS = 512                          ' Watchdog Timer Postscale Select bits
    '
    '@ CONFIG PWRTEN = ON                        ' Power up timer enabled
    '@ CONFIG BOREN = SBORDIS                    ' Brown-out Reset enabled in hardware only (SBOREN is disabled)
    '@ CONFIG BORV = 285                         ' VBOR set to 2.85 V nominal
    '
    @ CONFIG FOSC = INTIO67                      'Internal oscillator block
    OSCCON.6 = 1         '####################   111 = 16, 110 = 8
    OSCCON.5 = 0         '###### 16 MHz ######   101 =  4, 100 = 2
    OSCCON.4 = 1         '####################
    OSCTUNE.6 = 0        '##### PLL X 4 ######
    '@ CONFIG PLLCFG = ON          'Oscillator multiplied by 4
    '#########################################
    '#######   Make Ports Digital   ##########
    '#########################################
    '
    ANSELA = $00                                 'SET PORT A ALL DIGITAL
    ANSELB = $00                                 'SET PORT B ALL DIGITAL
    ANSELC = $00                                 'SET PORT C ALL DIGITAL
    ANSELD = $00                                 'SET PORT D ALL DIGITAL
    ANSELE = $00                                 'SET PORT E ALL DIGITAL
    '
    '==================================================================================================
    '===================================    INCLUDE FILES    ==========================================
    '==================================================================================================
    '
    '==================================================================================================
    '===================================    SET PIC PORTS    ==========================================
    '==================================================================================================
    '
    HCDATA var PORTC.5                               ' Pin 14 74HC595 
    HCCLK  var PORTD.4                               ' Pin 11 74HC595  
    HCLAT  var PORTC.7                               ' Pin 12 74HC595
    CIVP   VAR PORTA.5                               ' TO ICOM REMOTE PORT CI-V
    LCDP   VAR PORTB.0                               ' SERIAL LCD PORT (OPTIONAL)
    INFRA  VAR PORTD.7                               ' Infrared LED DATA
    'LED    VAR PORTC.0                               ' STATUS LED
    '
    '==================================================================================================
    '====================================    SET VARIABLES    =========================================
    '==================================================================================================
    '
    Leader VAR WORD                                  ' will be up to 900 for a 9mS leader pulse
    BtnVal VAR BYTE[32]                              ' holds 32 pulse results
    DByte1 VAR BYTE                                  ' address byte
    DByte2 VAR BYTE                                  ' inverse of address byte
    DByte3 VAR BYTE                                  ' command byte
    DByte4 VAR BYTE                                  ' inverse of command byte
    X      VAR BYTE                                  ' loop count
    Y      VAR BYTE                                  ' = DByte3 (command) for subroutines selection
    Z      VAR BYTE                                  ' Generic counter FOR-NEXT Loops (digits counter)
    RBdata VAR BYTE[6]                               ' Bytes array to store digits for frequency or memory   
    f1     VAR BYTE                                  ' Vol, SQL, MSB byte
    f2     VAR BYTE                                  ' Vol, SQL, LSB Byte 
    f3     VAR BYTE                                  ' BCD to BIN byte store for DEC calculations
    f4     VAR BYTE                                  ' BCD to BIN byte store for DEC calculations
    pattern   VAR Byte                                ' 74HC595 output pattern
    
    '
    '==================================================================================================
    '=====================================     SET CONSTANTS    =======================================
    '==================================================================================================
    '
    DL1    CON 800                                   ' > 8.5 ms pulse for NEC Protocol (Start) -  850 @ 4 MHz
    DL2    CON 110                                   ' > 1.5 ms pulse for NEC Protocol (read bit 0 or 1) @ 4 MHX
    LCDS   CON 16468                                 ' SERIAL LCD SPEED 16468 -> 9600
    LINE1  CON 128                                   ' LCD Line 1
    LINE2  CON 192                                   ' LCD Line 2
    I      CON 254                                   ' LCD general command
    CIVS   CON 84                                    ' "188"->4800, "84"->9600, "32"->19200 "813"->1200
    CIVA   CON $70                                   ' TRX address
    '
    '####################################################################################################################################################
    '
    '
    '##################################################################################################
    '#################################     PROGRAM STARTS HERE    #####################################
    '##################################################################################################
    '
    START:
    '
    CLEAR                                       '
    pattern = %00000000                         ' LED OFF
    gosub OUT_595
    PAUSE 200
    GOSUB LCDCLS
    PAUSE 10
    SEROUT2 LCDP,LCDS,["HELLO MALAKA"]
    pattern = %11111111                         ' LED ON
    gosub OUT_595
    pause 500
    pattern = %00000000                         ' LED OFF
    gosub OUT_595
    gosub LCDCLS	                             ' Clear LCD
    '
    '==================================================================================================
    '==============================   MAIN LOOP CHECKS FOR INFRARED COMMAND   =========================
    '==================================================================================================
    '
    MAIN: 
    '
    PULSIN INFRA,0,Leader                            ' Leader pulse is ~9mS low-going
    IF Leader < DL1 THEN Main                        ' Valid start burst check > 8.5 ms
    
    GOSUB READ32                                     ' Read 32 bytes (0-15 for address and 16-31 for command)   
    
    'GOTO MAIN                                       ' ONLY FOR TESTING AND READING VARIOUS NEC REMOTES
    
    GOSUB COMMANDS                                   ' GOTO Check Input Commands
    PAUSE 100
    GOTO MAIN
    '
    '==================================================================================================
    '===================================   VOLUME UP SUBROUTINE    ====================================
    '==================================================================================================
    '
    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:
    '
    GOSUB READVD
    
    f4 = f4 + 10                                                ' Increase volume by 10 units
    
    IF f3 < 2 AND f4 >= 99 THEN 
    	f4 = 0                                                  ' Make sure result is less than 100
    	f3 = f3 + 1                                             ' Increase hundreds by 1
    ELSEIF f3 > 1 AND f4 > 54 THEN                              ' If volume > 254 stay to 254 (max)
    	f3 = 2
    	f4 = 54
    ENDIF
    
    f1 = ((f3 / 10) << 4) + (f3 // 10)                          ' Convert bin to BCD
    f2 = ((f4 / 10) << 4) + (f4 // 10)                          ' Convert bin to BCD
    
    SEROUT2 CIVP,CIVS,[$FE,$FE,civa,$E0,$14,$01,f1,f2,$FD]      ' NEW VOLUME setting
    pause 50
    'GOSUB PRINTVAL                                              ' Only for testing and displaying actual volume
         
    RETURN
    '
    '==================================================================================================
    '=====================================    RECEIVED COMMANDS    ====================================
    '==================================================================================================
    '
    COMMANDS:
    '
    Y = DByte3
    '
    IF Y = 7 OR Y = 3 THEN               ' VOL - (added new NEC remote)
    	pattern = 1
    	GOSUB Out_595
    '	GOSUB VOLDOWN
    ENDIF
    IF Y = 21 OR Y = 2 THEN              ' VOL + (added new NEC remote)
    	pattern = 1
    	GOSUB Out_595
    	GOSUB VOLUP
    ENDIF
    
    RETURN
    '
    '################################################################################################################################
    '########################################################   CLEAR LCD   #########################################################
    '################################################################################################################################
    '
    LCDCLS:
    '
    SEROUT2 LCDP,LCDS,[254,1]           	' Clear LCD
    return
    '
    '################################################################################################################################
    '################################################################################################################################
    '################################################################################################################################
    '
    ' -------------------------------------------------------------------------------------------------------------------------------
    Out_595:
    '
    SHIFTOUT HCDATA,HCCLK,1,[pattern]                      ' send pattern to 1st 74HC595
    PULSOUT HCLAT, 5                                       ' latch outputs
    RETURN
    '
    '==================================================================================================
    '================================   READ 32 Bytes - Address and Command   =========================
    '==================================================================================================
    '
    READ32:
    '
    FOR X = 0 TO 31                                  ' grab 32 incoming pulses
    PULSIN INFRA,1,BtnVal[X]                         ' now measuring high-going pulse widths
    NEXT X
    
    FOR X = 0 TO 7                                   ' sort 1st 8 pulses
    IF BtnVal[X] > DL2 THEN                          ' > 150 x 10uS = > 1.5mS pulse period
             DByte1.0[X]=1
             ELSE
             DByte1.0[X]=0
    ENDIF
    NEXT X
     
    FOR X = 8 TO 15                                  ' sort 2nd 8 pulses, etc....
    IF BtnVal[X] > DL2 THEN
             DByte2.0[X-8]=1
             ELSE
             DByte2.0[X-8]=0
    ENDIF
    NEXT X
     
    FOR X = 16 TO 23
    IF BtnVal[X] > DL2 THEN
             DByte3.0[X-16]=1
             ELSE
             DByte3.0[X-16]=0
    ENDIF
    NEXT X
    
    FOR X = 24 TO 31
    IF BtnVal[X] > DL2 THEN
             DByte4.0[X-24]=1
             ELSE
             DByte4.0[X-24]=0
    ENDIF
    NEXT X
    
    DByte4 = ~ DByte4                                ' Reverse all the 8 bits to compare
    
    IF DByte3 <> DByte4 THEN
    	GOSUB LCDCLS
    	SEROUT2 LCDP,LCDS, [I,LINE1,"Command ERROR !"]
    	pause 500
    	GOSUB LCDCLS
    	pattern = 0
    	GOSUB out_595
    	GOTO MAIN
    ENDIF
    
    SEROUT2 LCDP,LCDS, [I,LINE1,"A : ",DEC3 DByte1, "-",BIN8 DByte1] ' PRINT ADDRESS
    SEROUT2 LCDP,LCDS, [I,LINE2,"C : ",DEC3 DByte3, "-",BIN8 DByte3] ' PRINT COMMAND
    
    RETURN
    '
    '==================================================================================================
    '==================================   Read Volume & SQL Data   ====================================
    '==================================================================================================
    '
    READVD:
    '
    SEROUT2 CIVP,CIVS,[$FE,$FE,CIVA,$E0,$14,Z,$FD]   ' Send this to the radio to read current SETTING
    SERIN2 CIVP,CIVS,[SKIP 6,f1,f2]                  ' Skip first 6 useless bytes and read next 2 bytes
    PAUSE 5                                          ' Give sometime to rest
    f3 = ((f1 >> 4) * 10) + (f1 & $0f)               ' Convert BCD to binary
    f4 = ((f2 >> 4) * 10) + (f2 & $0f)               ' Convert BCD to binary
    RETURN                                           ' Go back to set new Volume or Squelch
    '
    Well, that's all folks...
    Thanx in advance
    Fanias

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


    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:

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

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    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

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    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.

  10. #10
    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 ?

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    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 ?

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    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 : 2

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