In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Matthias09 wrote: Hey guys, I am just about writing a program to read an encoder. To not miss a step I count both on falling and rising edges of Channel A, whenever Channel B is high. Therefore I switch the edge detection mode of Wakeup Byte WKED_B after every counted step from rising to falling and vise versa. Now I encountered the problem, that when WKED_B = %00000000 it counts only the rising edge of Channel A (which sits on Bit 0), like it should. However, when I set the WKED_B = %11111111 it detects BOTH rising and falling edges, rather than only falling ones. How come and what to do? :) Here is my interrupt routine. Don't bother about the index channel part. That works fine. [code] 'Channel A Interrupt IF int_storage <> %0001 THEN Index_Channel 'count only, if A alone fires (other possible combinations: 0010: index fires, 0011: index + A fires) IF signal_B = 0 THEN ISR_Exit 'count only, if B is high toggle led1 IF edge = 0 THEN edge_0 'check the current edge detection mode, angle = angle + 1 'increment WKED_B = %11111111 'alter edge detection to falling edge on A edge = 0 'change edge detection mode variable to 0 for next interrupt toggle led3 GOTO ISR_Exit 'all done, leave edge_0: angle = angle - 1 'decrement WKED_B = %00000000 'alter edge detection to rising edge on A edge = 1 'change edge detection mode variable to 1 for next interrupt toggle led4 GOTO ISR_Exit 'all done, leave 'Index Channel Interrupt Index_Channel: 'if index fires (no mater if A also fires), then reset angle to 90 deg. WKEN_B = %11111100 'enable channel A interrupt (actually only has to be done after the first fire (as A is initally disabled). 'but to a routine would slow the process, which is not good. angle = 90 'reset angle Toggle Led2 [/code] This is what I do at startup: [code] PROGRAM Start Start: WKPND_B = %00000000 'clear pending register WKED_B = %00000000 'rising edge detect on the whole B Byte. WKEN_B = %11111101 'but only enable Bit 1 for interrupt for startup. All other Bits (except 0) can be used as I/Os without creating an interrupt edge = 1 'first edge detection mode is rising edge (I define: rising edge = 1, falling edge = 0) [/code] Thank you very much! Matthias ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=375331 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)