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
Send Topic Print
cmps03  who can help me [ compas ] (Read 2388 times)
vaolaritei
Junior Member
**




Posts: 62
cmps03  who can help me [ compas ]
06/23/10 at 9:46am
 
I want to add an cmps03 [ http://www.robot-electronics.co.uk/htm/cmps3tech.htm -- doc] and i dont know with what to start, in pic16f877 it's look simple and easy.  
 
Ideally I would if someone explains me how to implement it on the black-fin like an function for firmware , I have an  C code          [ http://www.robot-electronics.co.uk/files/cmps03_lcd03.c ] shows how to initialize the compass and how to read, if someone could help me with an idea or something more than I'm very much obliged. Thank you.
 
[ code ]
unsigned int get_cmps03(void)
{
unsigned int bearing;
 
     SEN = 1;                                                            // send start bit
     while(SEN);                                                      // and wait for it to clear
     ACKDT = 0;                                                      // acknowledge bit
     SSPIF = 0;
     SSPBUF = CMPS03_ADDR;                              // cmps03 I2C address
     while(!SSPIF);                                                // wait for interrupt
     SSPIF = 0;                                                      // then clear it.
     SSPBUF = 2;                                                      // address of register to read from - high byte of result  
     while(!SSPIF);                                                //  
     SSPIF = 0;                                                      //
     RSEN = 1;                                                      // send repeated start bit
     while(RSEN);                                                // and wait for it to clear
     SSPIF = 0;                                                      //
     SSPBUF = CMPS03_ADDR+1;                              // cmps03 I2C address - with read bit set
     while(!SSPIF);                                                // wait for interrupt
     SSPIF = 0;                                                      // then clear it.
     RCEN = 1;                                                      // start receiving
     while(!STAT_BF);                                          // wait for high byte of bearing
     bearing = SSPBUF<<8;                                    // and get it
     ACKEN = 1;                                                      // start acknowledge sequence
     while(ACKEN);                                                // wait for ack. sequence to end
     RCEN = 1;                                                      // start receiving
     while(!STAT_BF);                                          // wait for low byte of bearing
     bearing += SSPBUF;                                    // and get it
     ACKDT = 1;                                                      // not acknowledge for last byte
     ACKEN = 1;                                                      // start acknowledge sequence
     while(ACKEN);                                                // wait for ack. sequence to end
     PEN = 1;                                                            // send stop bit
     while(PEN);                                                      //
     return bearing;
}
Back to top
 
« Last Edit: 06/23/10 at 9:50am by vaolaritei »  
WWW good4u_tomi   IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: cmps03  who can help me [ compas ]
Reply #1 - 06/23/10 at 10:52am
 
You may have a problem because interface is 5V, not 3.3V.  However, it may be easiest just to use the PWM output from the compass and measuring the pulse with via Blackfin GPIO pin.
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
vaolaritei
Junior Member
**




Posts: 62
Re: cmps03  who can help me [ compas ]
Reply #2 - 06/24/10 at 6:30am
 
I look into srv firmware and i dont found a function for PWM, it's implemented?  an function Like
  int iPwm(....)//like timer, interval...
{
  
...
return number_count by PWM;
}
 
 
???
Back to top
 
« Last Edit: 06/24/10 at 6:31am by vaolaritei »  
WWW good4u_tomi   IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: cmps03  who can help me [ compas ]
Reply #3 - 06/24/10 at 6:59am
 
The closest we have to a function that reads PWM is found in srv.c.  Look at init_encoders(), read_encoders() and encoders() functions - these use GPIO-H14/15 and compute the pulse width of an incoming waveform.
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
vaolaritei
Junior Member
**




Posts: 62
Re: cmps03  who can help me [ compas ]
Reply #4 - 07/03/10 at 7:34am
 
Can some one help me with  an example about how i must read this encoders?
I can't understand?I will anyway I read something about it.  
 
Thanks.
Back to top
 
 
WWW good4u_tomi   IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: cmps03  who can help me [ compas ]
Reply #5 - 07/03/10 at 8:27am
 
The encoders() function counts measures the time duration of 4 pulse transitions (hi-low-hi-low) on each of GPIO-H14 and H15.  It then converts the data to a measurement of pulses per second (PPS), and returns the result as a packed integer - the upper 16 bits carry the left motor PPS and the lower 16 bits carry the right motor PPS.
 
This should work well for your application, provided the input signal frequency is 50Hz or higher.
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
vaolaritei
Junior Member
**




Posts: 62
Re: cmps03  who can help me [ compas ]
Reply #6 - 07/03/10 at 1:05pm
 
Thanks I will try that in this morning, but i have an max3232-se (3.0V <->5V)  and i thing to use it with a few diodes for sense, it's a possibility to work.
Back to top
 
 
WWW good4u_tomi   IP Logged
vaolaritei
Junior Member
**




Posts: 62
Re: cmps03  who can help me [ compas ]
Reply #7 - 07/03/10 at 2:29pm
 
can you see my comm. and and correct me where I wrong or did not know?
 
 init_encoders(); //init encoders
 
    t0 = readRTC();//read time 0 from qurtz  
    llast = *pPORTHIO & 0x4000; //? it's an bit from
    rlast = *pPORTHIO & 0x8000;
    ltime0 = ltime1 = rtime0 = rtime1 = 0;
    lcount = rcount = 0;
    
    while ((readRTC() - t0) < 40) {  // we count 40 ms
       lnew = *pPORTHIO & 0x4000;// here it's the pulse from motors so if was a change we count it
       if (llast != lnew) {//it's gone from 0 to 1
           llast = lnew;
           lcount++;// we count  the oscilation  
           if (lcount == 1)
               ltime0 = *pTIMER4_COUNTER;//?
           if (lcount == 3)
               ltime1 = *pTIMER4_COUNTER;
       }
       rnew = *pPORTHIO & 0x8000;// now we make same for rightmotor
       if (rlast != rnew) {
           rlast = rnew;
           rcount++;
           if (rcount == 1)
               rtime0 = *pTIMER4_COUNTER;
           if (rcount == 3)
               rtime1 = *pTIMER4_COUNTER;
       }
       if ((lcount>=3) && (rcount>=3))
           break;//why we stop here. when we have 4 count
    }
    if (!ltime1) ltime0 = 0;
    if (ltime1 < ltime0) ltime1 += PERIPHERAL_CLOCK;   // fix wraparound
    if (!rtime1) rtime0 = 0;
    if (rtime1 < rtime0) rtime1 += PERIPHERAL_CLOCK;   // fix wraparound
//++++++++
//why you do this check, fro negativ pulse
//if ltime1<ltime0 => our pulse1 is more little like pulse0?
//__________
    ltime1 -= ltime0;  // compute pulse width
    if (ltime1)  
       lcount = PERIPHERAL_CLOCK / ltime1;  // compute pulses per second
    else  
       lcount = 0;
 
    rtime1 -= rtime0;  
    if (rtime1)  
       rcount = PERIPHERAL_CLOCK / rtime1;  // compute pulses per second
    else  
       rcount = 0;
    
    return ((unsigned int)lcount << 16) + (unsigned int)rcount;
}
 
Back to top
 
« Last Edit: 07/03/10 at 2:36pm by vaolaritei »  
WWW good4u_tomi   IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: cmps03  who can help me [ compas ]
Reply #8 - 07/03/10 at 2:46pm
 
The timer only counts to 121000000 and then wraps around.  Because the counter is running at 121MHz, this happens about once per second.  
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
vaolaritei
Junior Member
**




Posts: 62
Re: cmps03  who can help me [ compas ]
Reply #9 - 07/03/10 at 2:47pm
 
I (am) still confuse, i will ask someone to explain me that.
 
BTW  if i make this compas to work, who i will make the robot to turn(in the same place) 5 degree at nord or west btw?
Back to top
 
« Last Edit: 07/03/10 at 3:04pm by vaolaritei »  
WWW good4u_tomi   IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: cmps03  who can help me [ compas ]
Reply #10 - 07/03/10 at 2:53pm
 
You can use the encoders() function in picoC to figure out the compass direction and then add some code to use the motors() command turn the robot until the target heading is found.
 
Though it's using a different compass and motor controller, you can see an example of picoC code that turns the robot to a desired heading here -  
    http://code.google.com/p/surveyor-srv1-firmware/source/browse/trunk/blackfin/srv /test4wd.c
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
vaolaritei
Junior Member
**




Posts: 62
Re: cmps03  who can help me [ compas ]
Reply #11 - 07/06/10 at 12:55pm
 
I use pin5 and pin6(rx1 and tx1) for an uart comunication what else pin can I use for modulation count of pwm?
I put an resistor 'to take down' 5V ->3V, i use an 10K to ground and 6.8K to pin with 5V.
Back to top
 
 
WWW good4u_tomi   IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: cmps03  who can help me [ compas ]
Reply #12 - 07/06/10 at 1:32pm
 
The existing encoder function is connected to pins 31 and 32 (GPIO H14 and H15)
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
vaolaritei
Junior Member
**




Posts: 62
Re: cmps03  who can help me [ compas ]
Reply #13 - 07/06/10 at 1:44pm
 
This is an soft uart.  
I am still confuse, if i use pwm to measure the pwm modulation why i need 2 wire, or i must use i2c, but for this i need an adapter 3V to 5V i have one max3232 but i burn himSad
Back to top
 
 
WWW good4u_tomi   IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: cmps03  who can help me [ compas ]
Reply #14 - 07/06/10 at 2:47pm
 
There are 2 channels supported by the encoders() function on pins 31 32.  You only need to use one of the channels
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
Pages: 1
Send Topic Print