Ok now, something very funny and absurd has happenedBefore explaining everything, I want to thank again everybody for their help.
I started to test codes and tried to find where was the exact problem. First of all, yes Robert you were right TMR0 instantly starting to run after "@ INT_ENABLE TMR0_INT" I replaced it's location first and then while looking for problem, I figured out that program is running "STANDUP" and "ENCOUNTER" programs only once, then I stopped calling "ENCOUNTER" and I saw that "STANDUP" is working very fine. Then I added another subroutine to program for testing, just toggling a pin and called it instead of "ENCOUNTER" there was no problem, everything was perfect.
So, what was the problem with "ENCOUNTER" I comment all lines of "ENCOUNTER" and started to comment out line by line to see where is the problem exactly. While I commenting out lines, I compiled and tried the program on every line of "ENCOUNTER".
Well now is the funny part, at the end commenting out of lines, while I was thinking "damn I tried all lines and got no error, now its back to old code and wont work as it is" it worked without any problem.. I didnt change any letter of "ENCOUNTER" just commented them in and out thats all, but it worked... Now it counts pulses and stops in right time..
I'm glad problem is solved, but does anyone have any idea about this stuation?
Here is working codes I compiled last.
Code:DEFINE OSC 16 INCLUDE "DT_INTS-14.bas" ' Base Interrupt System INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR0_INT, _kesme, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM ; enable Timer 0 interrupts ADCON1=7 'Defining Port usages and clearing ports for start TRISA=%00000000 TRISB=%00000000 TRISC=%11110000 TRISD=%00000011 PORTA=0 PORTB=0 PORTC=0 PORTD=0 'DEFINE ENCODER INPUTS SYMBOL EN1=PORTC.7 SYMBOL EN2=PORTC.6 SYMBOL EN3=PORTC.5 SYMBOL EN4=PORTC.4 SYMBOL EN5=PORTD.1 SYMBOL EN6=PORTD.0 'DEFINE MOTOR CONTROL OUTPUTS SYMBOL M1A=PORTB.7 SYMBOL M1B=PORTB.6 SYMBOL M2A=PORTB.5 SYMBOL M2B=PORTB.4 SYMBOL M3A=PORTB.3 SYMBOL M3B=PORTB.2 SYMBOL M4A=PORTD.7 SYMBOL M4B=PORTD.6 SYMBOL M5A=PORTD.5 SYMBOL M5B=PORTD.4 SYMBOL M6A=PORTD.3 SYMBOL M6B=PORTD.2 'DEFINE VARIABLES wsave VAR BYTE $70 SYSTEM ' alternate save location for W ' if using $70, comment wsave1-3 EN1PRE var BIT EN1NOW var BIT EN2PRE var BIT EN2NOW var BIT EN3PRE var BIT EN3NOW var BIT EN4PRE var BIT EN4NOW var BIT EN5PRE var BIT EN5NOW var BIT EN6PRE var BIT EN6NOW var BIT M1STEPSIZE VAR BYTE M2STEPSIZE VAR BYTE M3STEPSIZE VAR BYTE M4STEPSIZE VAR BYTE M5STEPSIZE VAR BYTE M6STEPSIZE VAR BYTE M1STATE VAR BYTE M2STATE VAR BYTE M3STATE VAR BYTE M4STATE VAR BYTE M5STATE VAR BYTE M6STATE VAR BYTE STANDC VAR BYTE M1C var BIT M2C var BIT M3C var BIT M4C var BIT M5C var BIT M6C var BIT walk_mode var byte duty_check var BIT duty_ctrl var BIT duty1 var byte duty0 var byte M1POWER var BIT M2POWER var BIT M3POWER var BIT M4POWER var BIT M5POWER var BIT M6POWER var BIT STANDUP_COUNT VAR BYTE CLEAR 'Clear all variables 'Defining starting values of some variables M1STEPSIZE=50 M2STEPSIZE=50 M3STEPSIZE=50 M4STEPSIZE=50 M5STEPSIZE=50 M6STEPSIZE=50 EN1PRE=EN1 EN2PRE=EN2 EN3PRE=EN3 EN4PRE=EN4 EN5PRE=EN5 EN6PRE=EN6 M1POWER=0 M2POWER=0 M3POWER=0 M4POWER=0 M5POWER=0 M6POWER=0 STANDUP_COUNT=50 pause 2000 walk_mode=0 'walk_mode defines which movement mode RHEX will use OPTION_REG=%10000100 TMR0=255 'Start Timer so interrupts and movement will start @ INT_ENABLE TMR0_INT 'RHEX IS STANDING UP 'Check every motor encoder value and stop releated motor if it reached to 'defined position 'MXC is used for motor running control, if a motor is reached to desired 'position and stopped, do not check and lose time on it STANDUP: gosub ENCOUNTER IF M1C=0 THEN IF M1STATE>=STANDUP_COUNT THEN M1POWER=1 M1C=1 STANDC=STANDC+1 ENDIF ENDIF IF M2C=0 THEN IF M2STATE>=STANDUP_COUNT THEN M2POWER=1 M2C=1 STANDC=STANDC+1 ENDIF ENDIF IF M3C=0 THEN IF M3STATE>=STANDUP_COUNT THEN M3POWER=1 M3C=1 STANDC=STANDC+1 ENDIF ENDIF IF M4C=0 THEN IF M4STATE>=STANDUP_COUNT THEN M4POWER=1 M4C=1 STANDC=STANDC+1 ENDIF ENDIF IF M5C=0 THEN IF M5STATE>=STANDUP_COUNT THEN M5POWER=1 M5C=1 STANDC=STANDC+1 ENDIF ENDIF IF M6C=0 THEN IF M6STATE>=STANDUP_COUNT THEN M6POWER=1 M6C=1 STANDC=STANDC+1 ENDIF ENDIF IF STANDC>=6 THEN @ INT_DISABLE TMR0_INT M1STATE=0 M2STATE=0 M3STATE=0 M4STATE=0 M5STATE=0 M6STATE=0 STANDC=0 PAUSE 2000 end ELSE GOTO STANDUP ENDIF end 'COUNTING PULSES FROM ENCODER OUTPUTS 'Read values of encoders and if they are different from previous value 'then it means, a transition is occured, so a pulse is given 'increase the releated encoder count 'Note: This will cause 2 counts for every pulse, not 1 count for 1 pulse. ENCOUNTER: EN1NOW=EN1 EN2NOW=EN2 EN3NOW=EN3 EN4NOW=EN4 EN5NOW=EN5 EN6NOW=EN6 IF EN1NOW!=EN1PRE THEN M1STATE=M1STATE+1 ENDIF EN1PRE=EN1NOW IF EN2NOW!=EN2PRE THEN M2STATE=M2STATE+1 ENDIF EN2PRE=EN2NOW IF EN3NOW!=EN3PRE THEN M3STATE=M3STATE+1 ENDIF EN3PRE=EN3NOW IF EN4NOW!=EN4PRE THEN M4STATE=M4STATE+1 ENDIF EN4PRE=EN4NOW IF EN5NOW!=EN5PRE THEN M5STATE=M5STATE+1 ENDIF EN5PRE=EN5NOW IF EN6NOW!=EN6PRE THEN M6STATE=M6STATE+1 ENDIF EN6PRE=EN6NOW return 'TMR0 INTERRUPT ROUTINE 'All motor movements are provided by this interrupt routine 'A PWM signal is created by using TMR0 timer and applied to 'motors, all PWM signals will be created by TMR0 for all movement types kesme: if walk_mode=0 then duty1=90 duty0=(256-duty1) if duty_check=0 then duty_ctrl=1 M1A=1 M1B=M1POWER M2A=M2POWER M2B=1 M3A=1 M3B=M3POWER M4A=M4POWER M4B=1 M5A=1 M5B=M5POWER M6A=M6POWER M6B=1 TMR0=duty1 endif if duty_check=1 then duty_ctrl=0 M1A=0 M1B=0 M2A=0 M2B=0 M3A=0 M3B=0 M4A=0 M4B=0 M5A=0 M5B=0 M6A=0 M6B=0 TMR0=duty0 endif endif if duty_ctrl=1 then duty_check=1 else duty_check=0 endif @ INT_RETURN end


Before explaining everything, I want to thank again everybody for their help.


Bookmarks