[Tinyos-commits] CVS: tinyos-1.x/tos/platform/msp430
LocalTimeMicroC.nc, NONE, 1.1 LocalTimeMicroM.nc, NONE,
1.1 MSP430DCOCalibC.nc, NONE, 1.1 MSP430DCOCalibM.nc, NONE,
1.1 MSP430ClockC.nc, 1.10, 1.11 MSP430ClockM.nc, 1.13, 1.14
Cory Sharp
cssharp at users.sourceforge.net
Sat Mar 26 19:47:29 PST 2005
Update of /cvsroot/tinyos/tinyos-1.x/tos/platform/msp430
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24163
Modified Files:
MSP430ClockC.nc MSP430ClockM.nc
Added Files:
LocalTimeMicroC.nc LocalTimeMicroM.nc MSP430DCOCalibC.nc
MSP430DCOCalibM.nc
Log Message:
Sliding-mode recalibration of the DCO with each ACLK overflow. This means
the DCO can be adjusted by about 0.35% every two seconds.
It also turns out that using the internal resistor of the MSP430, the DCO
changes about -0.35% / degC. So bottom line, this routine can account for
a change of about 0.5 degC / sec.
Also note that 4MHz is very near the top end of the maximum frequency
using the internal resistor. Room temperature calibration on one node I
tried is at 2004 out of a max 2016. This implies that the maximum
operating temperature to maintain 4MHz is around 33C or 92F, give or
take.
This routine all together adds about 6 bytes RAM (4 for calibration, 2 to
create a 32-bit 1MHz counter). ROM usage is about 250 bytes.
MSP430ClockC.nc: include the continuous calibration routine module.
MSP430ClockM.nc: ceiling the DCO calibration at 2016 not 2047.
LocalTimeMicro{C,M}.nc: provide local time in microseconds based on SMCLK
MSP430DCOCalib{C,M}.nc: the continuous calibration routine discussed above
--- NEW FILE: LocalTimeMicroC.nc ---
//$Id: LocalTimeMicroC.nc,v 1.1 2005/03/27 03:47:25 cssharp Exp $
/* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement
* is hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
* OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
// @author Cory Sharp <cssharp at eecs.berkeley.edu>
configuration LocalTimeMicroC
{
provides interface LocalTime;
}
implementation
{
components LocalTimeMicroM
, MSP430TimerC
;
LocalTime = LocalTimeMicroM;
LocalTimeMicroM.CounterFrom -> MSP430TimerC.TimerA;
}
--- NEW FILE: LocalTimeMicroM.nc ---
//$Id: LocalTimeMicroM.nc,v 1.1 2005/03/27 03:47:25 cssharp Exp $
/* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement
* is hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
* OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
// @author Cory Sharp <cssharp at eecs.berkeley.edu>
module LocalTimeMicroM
{
provides interface LocalTime;
uses interface MSP430Timer as CounterFrom;
}
implementation
{
typedef uint32_t to_size_type;
typedef uint16_t from_size_type;
typedef uint16_t upper_count_type;
enum
{
bit_shift_right = 0,
LOW_SHIFT_RIGHT = bit_shift_right,
HIGH_SHIFT_LEFT = 8*sizeof(from_size_type) - LOW_SHIFT_RIGHT,
//NUM_UPPER_BITS = 8*sizeof(to_size_type) - 8*sizeof(from_size_type) + bit_shift_right,
//OVERFLOW_MASK = (1 << NUM_UPPER_BITS) - 1,
};
upper_count_type m_upper = 0;
async command to_size_type LocalTime.read()
{
to_size_type rv = 0;
atomic
{
upper_count_type high = m_upper;
from_size_type low = call CounterFrom.read();
if( call CounterFrom.isOverflowPending() )
{
// If we signalled CounterFrom.overflow, that might trigger a
// Counter.overflow, which breaks atomicity. The right thing to do
// increment a cached version of high without overflow signals.
// m_upper will be handled normally as soon as the out-most atomic
// block is left unless Clear.clearOverflow is called in the interim.
// This is all together the expected behavior.
high++;
low = call CounterFrom.read();
}
{
to_size_type high_to = high;
to_size_type low_to = low >> LOW_SHIFT_RIGHT;
rv = (high_to << HIGH_SHIFT_LEFT) | low_to;
}
}
return rv;
}
async event void CounterFrom.overflow()
{
atomic
{
m_upper++;
/*
if( (m_upper & OVERFLOW_MASK) == 0 )
signal LocalTime.overflow();
*/
}
}
}
--- NEW FILE: MSP430DCOCalibC.nc ---
//$Id: MSP430DCOCalibC.nc,v 1.1 2005/03/27 03:47:25 cssharp Exp $
/* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement
* is hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
* OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
//@author Cory Sharp <cssharp at eecs.berkeley.edu>
configuration MSP430DCOCalibC
{
}
implementation
{
components MSP430DCOCalibM, LocalTimeMicroC, MSP430TimerC;
MSP430DCOCalibM.LocalTimeMicro -> LocalTimeMicroC;
MSP430DCOCalibM.Timer32khz -> MSP430TimerC.TimerB;
}
--- NEW FILE: MSP430DCOCalibM.nc ---
//$Id: MSP430DCOCalibM.nc,v 1.1 2005/03/27 03:47:25 cssharp Exp $
/* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement
* is hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
* OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*/
//@author Cory Sharp <cssharp at eecs.berkeley.edu>
module MSP430DCOCalibM
{
uses interface LocalTime as LocalTimeMicro;
uses interface MSP430Timer as Timer32khz;
}
implementation
{
uint32_t m_prev;
enum
{
TARGET_DELTA = 2L*1024L*1024L, // 2 seconds of a binary 1MHz clock
MAX_DEVIATION_FRACTION = 571, // (1/(.35%/2)), .35% is about the change of one calib tick
MAX_DEVIATION = (TARGET_DELTA / MAX_DEVIATION_FRACTION),
};
async event void Timer32khz.overflow()
{
uint32_t now = call LocalTimeMicro.read();
uint32_t now32khz = call Timer32khz.read();
int32_t dev;
// roughly adjust for any latency in servicing this interrupt
now = now - (now32khz << 5);
dev = (now - m_prev) - TARGET_DELTA;
m_prev = now;
if( (dev < -MAX_DEVIATION) || (dev > MAX_DEVIATION) )
{
uint16_t calib = ((BCSCTL1 & 7) << 8) | DCOCTL;
if( dev > MAX_DEVIATION )
{
// running too fast, slow down the DCO
if( calib > 0 )
{
calib--;
// if we're left the current RSELx, jump down into the middle of the one below
if( (calib & 0x0e0) == 0x0e0 )
calib -= (3 << 5);
}
}
else
{
// running too slow, speed up the DCO
if( calib < 0x7e0 ) // DCO calib can't go higher than 0x7e0
{
calib++;
// if we're leaving this RSELx, jump up into the middle of the one above
if( (calib & 0x0e1) == 0x0e1 )
calib += (3 << 5);
}
}
BCSCTL1 = (BCSCTL1 & ~0x07) | ((calib >> 8) & 0x07);
DCOCTL = calib & 0xff;
}
}
}
Index: MSP430ClockC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/platform/msp430/MSP430ClockC.nc,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** MSP430ClockC.nc 16 Mar 2005 08:56:45 -0000 1.10
--- MSP430ClockC.nc 27 Mar 2005 03:47:25 -0000 1.11
***************
*** 31,34 ****
--- 31,35 ----
{
components MSP430ClockM
+ , MSP430DCOCalibC //perpetual recalibration with each ACLK overflow
;
Index: MSP430ClockM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/platform/msp430/MSP430ClockM.nc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** MSP430ClockM.nc 24 Mar 2005 01:30:24 -0000 1.13
--- MSP430ClockM.nc 27 Mar 2005 03:47:25 -0000 1.14
***************
*** 192,195 ****
--- 192,199 ----
}
+ // if DCOx is 7 (0x0e0 in calib), then the 5-bit MODx is not useable, set it to 0
+ if( (calib & 0x0e0) == 0x0e0 )
+ calib &= ~0x01f;
+
set_dco_calib( calib );
}
More information about the Tinyos-commits
mailing list