In SX Microcontrollers, SX/B Compiler and SX-Key Tool, ems1965 wrote: I have my encoders working and now I want to get the counts to my "Propeller". If I send 2400 Baud from my Stamp2 for instance the propeller gets the data perfectly, but when I send them from my SX/B program I can't get it to work. I know it has something to do with the interrupts, but I'm not really versed on how to calculate the Clock cycles it consumes. How would I calculate a baud rate that will actually send 2400? [code] DEVICE SX28, OSCHS2, TURBO, STACKX, OPTIONX, BOR42 FREQ 50_000_000 ID "ENCODER" EncPort VAR RA ' encoder port TRIS_Enc VAR TRIS_A MaxVal CON 255 'encCheck VAR Byte EncodersOld VAR byte EncodersNew VAR byte Encoder_A_Count VAR byte Encoder_B_Count VAR byte tmpB1 VAR byte tmpB2 VAR Byte tmpB3 VAR Byte ' ========================================================================= INTERRUPT ' ========================================================================= ' Runs every 64 uS @ 4 MHz (no prescaler) ISR_Start: EncodersNew = EncPort TmpB1 = EncodersOld XOR EncodersNew ' compare old with new ' to work out which channels have changed TmpB2 = TmpB1 << 1 ' make single bit that shows change on A or B phase TmpB1 = TmpB1 OR TmpB2 EncodersOld = EncodersOld << 1 ' make direction bits by comparing old A with new B EncodersOld = EncodersOld XOR EncodersNew ' xor old A with new B IF TmpB1.3 = 1 THEN IF EncodersOld.3 = 1 THEN INC Encoder_A_Count ELSE DEC Encoder_A_Count Encoder_A_Count Min 0 ENDIF ENDIF ' ========================================================================= IF tmpB1.1 = 1 THEN IF EncodersOld.1 = 1 THEN INC Encoder_B_Count ELSE DEC Encoder_B_Count Encoder_B_Count Min 0 ENDIF ENDIF EncodersOld=EncodersNew 'ISR_Exit: RETURNINT ' ========================================================================= PROGRAM Start NOSTARTUP ' ========================================================================= Start: EncodersNew = EncPort EncodersOld = EncodersNew Encoder_A_Count = 0 Encoder_B_Count = 0 OPTION = $88 ' interrupt, no prescaler Main: Do Serout RC.7,T2400,Encoder_A_Count LOOP Thanks, Eric [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=148015 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)