Welcome, Guest. Please Login.
Surveyor Corporation Surveyor SRV-1
Home Help Search Login

Surveyor Robotics Forum

Welcome to the user support forum for Surveyor SRV-1 robots, SRV-1 robot controllers and SVS stereo vision systems. To register for this forum, please send an email to support@surveyor.com which includes your desired forum user name, your registration email address, and a brief explanation of why you wish to join, and we will create a forum account for you.

Please note that there is a Search button in the forum toolbar for forum topics. Another effective search method for the entire surveyor.com site is to use Google, e.g. "xyz site://www.surveyor.com" where "xyz" is the search topic.



Pages: 1 2 3 4 5
Send Topic Print
Adding optical mouse sensor for dead reckoning (Read 53589 times)
NickK1066
Senior Member
****




Posts: 299
Re: Adding optical mouse sensor for dead reckoning
Reply #15 - 08/14/08 at 1:39am
 
Just an aside - use brackets with the #define otherwise you'll wonder why at some point your if statement is not working right..
Code:
#define	raiseClock()		{*pPORTHIO_SET |= 0x2000;} 


 
This caters for something like:
Code:
#define	raiseClock()		*pPORTHIO_SET |= 0x2000; debug("raised"); 


 
Which would fail in the if statement:
Code:
if <condition>
	 raiseClock();
... more code..
 


 
Same goes for params in #define FOO(x)    ((x)<<8)
 
Perhaps not the best place to mention this and polute the thread but I thought I'd mention the pitfall.
 
 
Back to top
 
 

  IP Logged
NickK1066
Senior Member
****




Posts: 299
Re: Adding optical mouse sensor for dead reckoning
Reply #16 - 08/14/08 at 1:52am
 
Quote from Lefteris on 08/14/08 at 1:30am:

This should work? Right? Well it does not Sad . Trying opticalWrite(0x00,0x01) which should force the sensor to awake mode(much more bright led) did nothing when with the ATmega8 with the same functions it worked.

 
Hmm ok, the same mechanism works on one hardware and the other then the only logical deduction could be:
a) the timing is different - the faster blackfin may be causing a sharper signal that may not be sensed correctly (is 28 the right value for blackfin?)
b) the I/O code isn't creating a output
c) the electrical characteristics are in correct - (is the output 3.3V for example)
 
a) a 'cope could show this.
b) is PORTH_FER cleared for PH14 & PH15 ? Have you attached a voltmeter to check the voltage change if you code up a 2 second on/off alternating pulse? Is the PORTH_POLAR/EDGE/BOTH set right?
c) volt meter again..
 
Back to top
 
« Last Edit: 08/14/08 at 1:54am by NickK1066 »  

  IP Logged
Lefteris
Senior Member
****




Posts: 274
Re: Adding optical mouse sensor for dead reckoning
Reply #17 - 08/14/08 at 4:17am
 
Thanks for your answers nick, I am still learning this and I might be omitting some vital parts of testing. So well ... I took out my multimeter and tried to measure the difference in voltage.
 
One lead to the PH15 pin and one to GND. Thing is that no matter what I did even without launching this code to alternate between logical high and low every 2 secs the voltage difference was stuck at 3.24 volts. That's kind of strange since it was supposed to alternate between that and logical low.
Code:
case 'R':
				//our escape route, press X and we are getting out of here
				bFlag = 0;
				while(bFlag != 1)
				{
					if(uart0GetChar(&ch1))
					{
						if(ch1 == 'x' || ch1 == 'X')
						bFlag = 1;
						uart0SendString("Ended");
					}
					delayMS(2000);
					*pPORTHIO_SET |= 0x2000;
					*pPORTHIO_SET |= 0x8000;
					delayMS(2000);
					*pPORTHIO_CLEAR |= 0x2000;
					*pPORTHIO_CLEAR |= 0x8000;
					uart0SendString("Sending...");
					uart0SendChar('\n');
				} 


 
As for the polarity isn't the polar->0 , edge->0 Both->X the default and the one we want? That is what the HRM says :  
POLAR EDGE BOTH Effect of MMR Settings
0           0        X     Pin that is high reads as 1; pin that is low reads as 0
 
But still ... what could be wrong and I have no alternating voltages? I mean even before I set PH14 and PH15 pins the voltage is 3.24 there. It's weird.
Back to top
 
 

http://www.realintelligence.net - The real intelligence project || http://lefteris.realintelligence.net - My blog
  IP Logged
NickK1066
Senior Member
****




Posts: 299
Re: Adding optical mouse sensor for dead reckoning
Reply #18 - 08/14/08 at 5:01am
 
I see that you're used H14 & H15 - have you checked to see if the code for the x/y axis accelerometer isn't resetting your configuration to input?
Back to top
 
 

  IP Logged
NickK1066
Senior Member
****




Posts: 299
Re: Adding optical mouse sensor for dead reckoning
Reply #19 - 08/14/08 at 5:14am
 
0x8000 = bit 15 - H15
0x4000 = bit 14 - H14
0x2000 = bit 13 - H13
 
Back to top
 
 

  IP Logged
NickK1066
Senior Member
****




Posts: 299
Re: Adding optical mouse sensor for dead reckoning
Reply #20 - 08/14/08 at 5:16am
 
Quote from NickK1066 on 08/14/08 at 5:01am:
I see that you're used H14 & H15 - have you checked to see if the code for the x/y axis accelerometer isn't resetting your configuration to input?

 
Looking at the programming model - we should at least get some activity from the port.
 
Have you tried poking the lasers instead with that code? Do they switch on/off every 2 seconds?
Back to top
 
 

  IP Logged
Lefteris
Senior Member
****




Posts: 274
Re: Adding optical mouse sensor for dead reckoning
Reply #21 - 08/14/08 at 5:38am
 
Yeah I had tried that with the lasers they do change from 3.24V to 0V when they are closed
 
EDIT: Just saw that you made more than 1 post. Will check all those things when I get back home. Thanks for pointing out the wrong hex conversion.
Back to top
 
« Last Edit: 08/14/08 at 5:55am by Lefteris »  

http://www.realintelligence.net - The real intelligence project || http://lefteris.realintelligence.net - My blog
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Adding optical mouse sensor for dead reckoning
Reply #22 - 08/14/08 at 7:02am
 
You should comment out or delete the init_accel() call at the beginning of main.c - it does set up H14 and H15 as inputs.
 
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
Lefteris
Senior Member
****




Posts: 274
Re: Adding optical mouse sensor for dead reckoning
Reply #23 - 08/14/08 at 7:51am
 
That must be it. See? Whenever I measured those pins with the multimeter they were always at 3.4 V no matter what I did to them. Which was odd. That must be it. I never commented out the accelerometer code. darn , I will go do it asap.
Back to top
 
 

http://www.realintelligence.net - The real intelligence project || http://lefteris.realintelligence.net - My blog
  IP Logged
spikey
YaBB Newbies
*




Posts: 43
Re: Adding optical mouse sensor for dead reckoning
Reply #24 - 08/14/08 at 11:19am
 
Not sure if it really matters but I think the delay should be slighly larger with the blackfin.
The peripheral clock is set to 121649000Hz (by the default srv firmware), so a 250ns delay should be 121649000 * (250 * (10^(-9))) = 30.41225. but maybe 28 is enough to compensate for other operations
Back to top
 
 
  IP Logged
Lefteris
Senior Member
****




Posts: 274
Re: Adding optical mouse sensor for dead reckoning
Reply #25 - 08/14/08 at 2:29pm
 
Yeah spikey 30 ticks is the proper delay but I thought as you said that all the other calculations that the processor will be doing will compensate for it one way or the other. Ofcourse ... in the datasheet it says 250ns minumum, so I guess it is all the same Smiley
 
Anyway, I managed to write to the sensor with the blackfin now. Could turn it from awake mode to sleep mode and back by writting to its configuration register. When I tried to read from it I had some problems though. So I want to ask somethings.
 
The datasheet mentions that we need to go to Hi-Z state after the last address bit. Isn't HI-Z state just going to input mode?
 
Here is the code:
Code:
u8 opticalRead(u8 rAddr)
{
	int i = 0 ;
	u8 data = 0x00;

	//we make sure the address has '0' as its MSB
	rAddr &= ~0x80;
	//we send the register's address
	for(i=8;i>=1;i--)
	{	
		if(isSet(rAddr,i-1))
			raiseData();
		else
			lowerData();
		lowerClock(); //SDA is changed on falling edges of the clock
		delay(30);
		
		raiseClock(); //and the sensor reads it on rising edges
		delay(30);	
	}
	
	//we go to Hi-Z state
	*pPORTHIO_DIR &= ~0x8000;
	*pPORTHIO &= ~0x8000;
	*pPORTHIO_INEN |= 0x8000;
	delayMS(100); //wait 100 microsecond
	for(i=8;i>=1;i--)
	{
		lowerClock();//SDA is changed on falling edges of the clock
		if(*pPORTHIO & 0x8000)
			setBit(data,i-1);
		else
			clearBit(data,i-1);
			
		delay(30);
		
		raiseClock();
		delay(30);
	}
	
	*pPORTHIO_INEN &=~0x8000; //back to output
	*pPORTHIO_DIR |= 0x8000;
	
	return data;
	
} 


 
The send address part of the function should be working 100% since it is the same as the opticalWrite function's. Problem is no matter which register I try to read I get an 0xFF byte. Which means that :
if(*pPORTHIO & 0x8000) is always true. So it means that either the sensor does not send the data or it does but the microcontroller does not recognize them since PH15 is always at logical high.  
 
Maybe the way I go HI-Z state is wrong? Or should I set the polar/edge/both too? But I think the default value logical high reads as 1 and logical low as 0 is what I need, right?
Back to top
 
 

http://www.realintelligence.net - The real intelligence project || http://lefteris.realintelligence.net - My blog
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Adding optical mouse sensor for dead reckoning
Reply #26 - 08/15/08 at 1:28am
 
Right - input mode should give you the high-Z
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
Lefteris
Senior Member
****




Posts: 274
Re: Adding optical mouse sensor for dead reckoning
Reply #27 - 08/15/08 at 3:55am
 
I see. Well then back to square 1. Being able to write to the registers of the sensor but not being able to read from them. I have no idea what it might be. A friend suggested that maybe the sensor is not as strong as the microcontroller and can't handle the SDA line due to the length of the wire when it is relinquished from the microcontroller.
 
I will try to shrink the wire to the absolute minimum when the SRV re-charges.
Back to top
 
 

http://www.realintelligence.net - The real intelligence project || http://lefteris.realintelligence.net - My blog
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Adding optical mouse sensor for dead reckoning
Reply #28 - 08/15/08 at 7:12am
 
It will be a few days before I can get to this, but I will try to track down one of those mice or else try to wire up a circuit with an ADNS2610 to see if I can get the interface to work.
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
Lefteris
Senior Member
****




Posts: 274
Re: Adding optical mouse sensor for dead reckoning
Reply #29 - 08/15/08 at 2:46pm
 
Thanks admin. I too will try to do anything I can think of to try and find what the problem might be. It drives me nuts, being able to write but not read from the sensor.
Back to top
 
 

http://www.realintelligence.net - The real intelligence project || http://lefteris.realintelligence.net - My blog
  IP Logged
Pages: 1 2 3 4 5
Send Topic Print