Go to Post Multitasking is a myth. - DonRotolo [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 28-02-2006, 23:29
Rickertsen2 Rickertsen2 is offline
Umm Errr...
None #1139 (Chamblee Gear Grinders)
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2002
Location: ATL
Posts: 1,421
Rickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant future
Send a message via AIM to Rickertsen2 Send a message via Yahoo to Rickertsen2
loosing encoder count

I am having a terrible problem where my encoders gradually loose track of position as if they are dropping ticks or something.

Is it possible that maybie the secret IFI stuff is using High priority interrupts that take a long time and are causing the LP ISR not to execute? I notice that occasionally characters printed to the terminal are dropped as well. Then again the terminal printing thing could be a buffer overrun caused by printing faster than the UART can transmit.

The relevant code is below:

Code:
#pragma code
#pragma interruptlow InterruptHandlerLow save=PROD,section(".tmpdata")
//#pragma interruptlow InterruptHandlerLow,section(".tmpdata")
void InterruptHandlerLow ()     
{
	HandleTurretInterrupts();
...

All you really need to look at here is the HandleTurretInterrupts() function.
Code:
/*
 * FILE: turret.h
 *
 * Responsible for turret limits, keeping
 * track of it's absolute position and performing the 'homing' sequence.
 */
//==================================================
#include "turret.h"
#include "boolean.h"
#include "hardware.h"
#include <stdio.h>
#include <p18f8722.h>

//--- private variables ---//
boolean pan_homed = false;
boolean tilt_homed = false;

//the current position of the pan and tilt axis
volatile signed int pan_position = 0;
volatile signed int tilt_position = 0;

//used for 'thread' synchronization probably unnecessary after i made the change to diable interrupts during access like kevin did in his code. Currently not used
volatile boolean panTicksBusy	= false;
volatile boolean tiltTicksBusy	= false;


//--- Private Prototypes --//
void Pan_Routine(void); //
void Tilt_Routine(void);

//-------Functions --------//

//used by all other pars of the code to set the pan axis speed.
void setPanSpeed(signed char speed){
	rc_turret_pan = oi_joy_turret_pan;
	
	//make sure we don't override the homin sequence
	#ifdef TURRET_AUTO_HOMING
		if(!pan_homed) return;
	#endif
	//limit range of motion
	#ifdef USE_TURRET_PAN_LIMIT
		panTicksBusy	= true;
		rc_turret_pan = ((rc_turret_pan<127)&&(pan_position<=PAN_MIN))? 127 : rc_turret_pan;
		rc_turret_pan = ((rc_turret_pan>127)&&(pan_position>=PAN_MAX))? 127 : rc_turret_pan;
		panTicksBusy	= false;
	#endif
}

//used by all other parts of the code to set the speed of the tilt axis.
void setTiltSpeed(signed char speed){
	rc_turret_tilt = oi_joy_turret_tilt;
	
	//make sure we don't override the homin sequence
	#ifdef TURRET_AUTO_HOMING
		if(!tilt_homed) return;
	#endif
	//limit range of motion
	#ifdef USE_TURRET_TILT_LIMIT
		tiltTicksBusy	= true;
		rc_turret_tilt = ((rc_turret_tilt<127)&&(tilt_position<=TILT_MIN))? 127 : rc_turret_tilt;
		rc_turret_tilt = ((rc_turret_tilt>127)&&(tilt_position>=TILT_MAX))? 127 : rc_turret_tilt;		
		tiltTicksBusy	= false;
	#endif
}

//Finds the 0 position of the turret based on the limit switches.
//The axis rotate in the direction of the limit switches until the limit switches are reached. When this happens, movement stops
//and the position cound is set to 0. 
void TurretHome(void){
	#ifdef TURRET_AUTO_HOMING
	//---pan---
	if(pan_homed){
		//do nothing
	}else{
		//find our home position
		if(rc_sw_pan_home){
			pan_homed 		= true;
			 panTicksBusy	= true;
			 pan_position	= 0;
			 panTicksBusy	= false;
			rc_turret_pan	= 127;
		}else{
			rc_turret_pan	= PAN_HOME_SPEED;
		}
	}
	//---tilt---
	if(tilt_homed){
		if(rc_sw_tilt_home){
			tilt_position = 0;	
		}
		//do nothing/**/
	}else{
		//find our home position
		if(rc_sw_tilt_home){
			tilt_homed 		= true;
			 tiltTicksBusy	= true;
			 tilt_position	= 0;
			 tiltTicksBusy	= false;
			rc_turret_tilt	= 127;
		}else{
			rc_turret_tilt	= TILT_HOME_SPEED;
		}
	}
	#endif
}
void TurretRoutine(void){
	TurretHome();
	#ifdef PRINT_TURRET_STATUS
		//printf("TURR pl:%u, tl:%u, ph:%u, th:%u, p:%d,		t:%d\n\r",rc_sw_pan_home,rc_sw_tilt_home,pan_homed,tilt_homed,pan_position,tilt_position);
		//printf("TURR pl:%u, tl:%u, pan:%d, tilt:%d\n\r",rc_sw_pan_home,rc_sw_tilt_home,pan_position,tilt_position);
		//printf("tilt:%d		pan:%d\n\r",tilt_position,pan_position);
		//printf("Pan:%d   	Tilt:%d\n\r",rc_turret_pan,rc_turret_tilt);
	#endif
}

//--- called by the ISR in user_routines_fast.c ---
void HandleTurretInterrupts(void){
	if(INTCON3bits.INT2IF) //this is a tilt encoder tick (rising edge of tilt A line)
	{
		INTCON3bits.INT2IF = 0; //clear the flag
		/*
		//we have an concurrent access error?
		if(tiltTicksBusy)
		{
			 printf("p!!!!!!!");	
			 return;
		}
		*/
		tiltTicksBusy = true;
		if(rc_dig_in03) {						// tilt B
			 tilt_position++;
		} else {
			tilt_position--;
		}
		tiltTicksBusy = false;
	}
	if(INTCON3bits.INT3IF) //this is a pan encoder tick (rising edge of pan A line)
	{
		INTCON3bits.INT3IF = 0; //clear the flag
		/*
		//we have an acces violation
		if(panTicksBusy){
			printf("p!!!!!!!");
			return;
			
		}
		*/
		panTicksBusy = true;
		if(rc_dig_in04) {						// pan B
			pan_position--;
		} else {
			pan_position++;
		}
		panTicksBusy = false;
	}
}
//-- return whether or not the axis' are homed and ready to use --
boolean isPanHomed(){
	return pan_homed;
}
boolean isTiltHomed(){
	return tilt_homed;
}

//--- configures the turrent encoders ---
void InitTurret(void){
	//--- initialize positions to 0 ---
	//panTicksBusy	= true;
	//tiltTicksBusy	= true;
	 pan_position	= 0;
	 tilt_position	= 0;
	//panTicksBusy	= false;
	//tiltTicksBusy	= false;
	/*==== ENCODER PINS ====
	 *Pan	A: INT2/RB2/digital input 01
	 *Tilt	A: INT3/RB3/digital input 02
	 *Pan	B: RB4/digital input 3
	 *Tilt	B: RB5/digital input 4
     */
	//--- setup pins as inputs ---
	rc_dig_iomode_01 = INPUT;
	rc_dig_iomode_02 = INPUT;
	rc_dig_iomode_03 = INPUT;
	rc_dig_iomode_04 = INPUT;
	
	//--- setup tilt encoder interrupt (INT2/RB2/digital input 01/pan A) ---
	INTCON3bits.INT2IF  = 0; //make sure flag is clear
	INTCON2bits.INTEDG2	= 1; //interrupt on low->high
	INTCON3bits.INT2IP	= 0; //make it low priority
	INTCON3bits.INT2IE	= 1; //enable it

	//-- setup pan encoder interrupt (INT3/RB3/digital input 02/tilt A) ---
	INTCON3bits.INT3IF =  0; //make sure flag is clear
	INTCON2bits.INTEDG3	= 1; //interrupt on low->high
	INTCON2bits.INT3IP	= 0; //make it low priority
	INTCON3bits.INT3IE	= 1; //enable it
	
	printf("encoders initialized\n");
	//OpenRB2INT(PORTB_CHANGE_INT_ON & FALLING_EDGE_INT & PORTB_PULLUPS_OFF);
	
}

//-- Functions to return the position of the axis --
signed int getPanPos(void){
	signed int temp;
	//panTicksBusy = true;
	INTCON3bits.INT3IE = 0; //temporarily diable
	 temp = pan_position;
	INTCON3bits.INT3IE = 1; //enable
	//panTicksBusy = false;
	return temp;
}

signed int getTiltPos(void){
	signed int temp;
	//tiltTicksBusy = true;
	INTCON3bits.INT2IE = 0;
	 temp = tilt_position; 
	INTCON3bits.INT2IE = 1;
	//tiltTicksBusy = false;
	return temp ;
}
__________________
1139 Alumni

Last edited by Rickertsen2 : 28-02-2006 at 23:33.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Encoder Code Kevin Watson Programming 47 18-02-2008 12:56
Serial Driver and 2K6 Encoder Driver Not compatible Tom Bottiglieri Programming 6 12-02-2006 01:11
Need Help with Encoder - Won't Count Clicks Kingofl337 Programming 5 16-02-2005 18:30
Updated Encoder Code Available Kevin Watson Programming 2 04-01-2005 01:00
quick question: TIMERS Xufer Programming 58 18-03-2004 08:49


All times are GMT -5. The time now is 03:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi