In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Rsadeika wrote: I thought I had the freq and interrupt concept under control, but I am running into some problems. I have listed below the IR remote control program. Basically, the problem is, when I change the device freq in the program to anything but 4Mhz, the program does not work as expected. I make a special effort to make sure all the settings are correct, i.e. freq is correct sellection for the oscillator type., and so forth. My general understanding is that in non time critical interrupts, the freq can be changed without any problems in the program. In the interrupt below, I thought that changing the device freq to, lets say, 8Mhz should not have any affect, but it does, the progran does not work. It seems to me that the interrupt below is one of those non time critical applications. So now I am completely lost. At a later date I am going to try to implement an IR LED, as a VP along with the IR detector, for communications purposes, that will be time critical, so I need to figure out the problem at hand. Any help or advice would be appreciated. Ray *******Code****** ' ========================================================================= ' ' File...... XGbot.SXB ' Purpose... ' Author.... R Sadeika ' E-mail.... ' Started... ' Updated... ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- IR var rc.0 ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- Power con 21 ChUp con 16 ChDn con 17 VolUp con 18 VolDn con 19 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- cmdCode VAR Byte ' IR command code (7 bits) cmdWork VAR Byte ' work space for cmd byte bitCount VAR Byte ' track bits received bitWidth VAR Byte ' measure bit width flags VAR Byte rxCmd VAR flags.0 ' receiving command rxBit VAR flags.1 ' measuring bit width? hasCmd VAR flags.2 ' command code available temp1 VAR Byte ' subroutine work vars temp2 VAR Byte temp3 VAR Byte ' ------------------------------------------------------------------------- INTERRUPT ' ------------------------------------------------------------------------- ISR_Start: ASM JB hasCmd, ISR_Exit ' exit if holding command JB rxCmd, Check_Bit ' receiving now? JB IR, ISR_Exit ' exit if IR line idle Start_Packet: SETB rxCmd ' set rx flags SETB rxBit CLR cmdWork ' clear work vars CLR bitWidth CLR bitCount JMP ISR_Exit Check_Bit: JNB IR, Update_BitWidth ' still in bit? JNB rxBit, ISR_Exit ' in idle period? CLRB rxBit ' no, clear bit flag CJA bitCount, #0, Test_DBit ' start or data bit? Test_SBit: CJA bitWidth, #74, Next_Bit ' proper start bit? CLR rxCmd ' no, reset JMP ISR_Exit Test_DBit: CLC RR cmdWork ' prep for next bit CJB bitWidth, #34, Next_Bit ' "1" bit? SETB cmdWork.6 ' yes, set it Next_Bit: CLR bitWidth ' clear for next bit INC bitCount ' update count CJB bitCount, #8, ISR_Exit ' done? SETB hasCmd ' set available flag MOV cmdCode, cmdWork ' copy work to output CLRB rxCmd ' clear rx flag JMP ISR_Exit Update_BitWidth: INC bitWidth ' else inc width SETB rxBit ' refresh in bit flag ENDASM ISR_Exit: RETURNINT 104 ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- LED1 sub ProcessCode sub Stop sub GoFore sub GoBack sub LF sub LB sub RF sub RB1 sub ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: ' initialization code here PLP_A = %0000 ' pull-up unused pins PLP_B = %00000000 PLP_C = %00000000 ' make LED pins outputs OPTION = $88 ' interrupt, no prescaler Main: IF hasCmd = 0 THEN Main ' wait for new code ProcessCode hasCmd = 0 GOTO Main end ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- ProcessCode: IF cmdCode = Power then Stop 'Power = Stop IF cmdCode = ChUp then GoFore IF cmdCode = ChDn then GoBack IF cmdCode = VolUp then LED1 IF cmdCode = VolDn then LED1 IF cmdCode = 0 then LF IF cmdCode = 3 then LB IF cmdCode = 1 then RF IF cmdCode = 4 then RB1 return Stop: HIGH rc.3 'Wire 5 Red LS M1 HIGH rc.2 'Wire 6 Yellow LS M1 HIGH rc.1 'Wire 7 Black RS M2 HIGH rc.0 'Wire 8 White RS M2 return GoFore: LOW rc.3 'Wire 5 LS LOW = 0 HIGH rc.2 'Wire 6 LS HIGH = 1 HIGH rc.1 'Wire 7 RS LOW rc.0 'Wire 8 RS return GoBack: HIGH rc.3 'Wire 5 LS LOW rc.2 'Wire 6 LS LOW rc.1 'Wire 7 RS HIGH rc.0 'Wire 8 RS return LF: LOW rc.3 HIGH rc.2 return LB: HIGH rc.3 LOW rc.2 return RF: HIGH rc.1 LOW rc.0 return RB1: LOW rc.1 HIGH rc.0 return LED1: HIGH rc.1 pause 2000 LOW rc.1 return ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=115967 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)