SAMV71 Xplained Ultra Software Package 1.3

rtc_calib.c

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2014, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /**
00031  * \file
00032  *
00033  * Interface for Real Time Clock calibration (RTC) .
00034  *
00035  */
00036 
00037 /*----------------------------------------------------------------------------
00038  *        Headers
00039  *----------------------------------------------------------------------------*/
00040 
00041 #include "board.h"
00042 
00043 const RTC_PPMLookup PPM_Lookup[] =
00044 {
00045   /* Tmp  PPM  Neg Hi  Correction */
00046     {-40, -168 ,0, 1 ,22 },
00047     {-39, -163 ,0, 1 ,23 },
00048     {-38, -158 ,0, 1 ,24 },
00049     {-37, -153 ,0, 1 ,25 },
00050     {-36, -148 ,0, 1 ,25 },
00051     {-35, -143 ,0, 1 ,26 },
00052     {-34, -138 ,0, 1 ,27 },
00053     {-33, -134 ,0, 1 ,28 },
00054     {-32, -129 ,0, 1 ,29 },
00055     {-31, -124 ,0, 1 ,31 },
00056     {-30, -120 ,0, 1 ,32 },
00057     {-29, -116 ,0, 1 ,33 },
00058     {-28, -111 ,0, 1 ,34 },
00059     {-27, -107 ,0, 1 ,36 },
00060     {-26, -103 ,0, 1 ,37 },
00061     {-25, -99,  0, 1 ,38 },
00062     {-24, -95,  0, 1 ,40 },
00063     {-23, -91,  0, 1 ,42 },
00064     {-22, -87,  0, 1 ,44 },
00065     {-21, -84,  0, 1 ,45 },
00066     {-20, -80,  0, 1 ,48 },
00067     {-19, -76,  0, 1 ,50 },
00068     {-18, -73,  0, 1 ,53 },
00069     {-17, -70,  0, 1 ,55 },
00070     {-16, -66,  0, 1 ,58 },
00071     {-15, -63,  0, 1 ,61 },
00072     {-14, -60,  0, 1 ,64 },
00073     {-13, -57,  0, 1 ,68 },
00074     {-12, -54,  0, 1 ,71 },
00075     {-11, -51,  0, 1 ,76 },
00076     {-10, -48,  0, 1 ,80 },
00077     {-9 ,-45 ,  0, 1 ,86 },
00078     {-8 ,-43 ,  0, 1 ,90 },
00079     {-7 ,-40 ,  0, 1 ,97 },
00080     {-6 ,-37 ,  0, 1 ,105},
00081     {-5 ,-35 ,  0, 1 ,111},
00082     {-4 ,-33 ,  0, 1 ,117},
00083     {-3 ,-30 ,  0, 0 ,6  },
00084     {-2 ,-28 ,  0, 0 ,6  },
00085     {-1 ,-26 ,  0, 0 ,7  },
00086     {0 ,-24 ,   0, 0 ,7  },
00087     {1 ,-22 ,   0, 0 ,8  },
00088     {2 ,-20 ,   0, 0 ,9  },
00089     {3 ,-18 ,   0, 0 ,10 },
00090     {4 ,-17 ,   0, 0 ,10 },
00091     {5 ,-15 ,   0, 0 ,12 },
00092     {6 ,-13 ,   0, 0 ,14 },
00093     {7 ,-12 ,   0, 0 ,15 },
00094     {8 ,-11 ,   0, 0 ,17 },
00095     {9 ,-9 ,    0, 0 ,21 },
00096     {10 ,-8 ,   0, 0 ,23 },
00097     {11 ,-7 ,   0, 0 ,27 },
00098     {12 ,-6 ,   0, 0 ,32 },
00099     {13 ,-5 ,   0, 0 ,38 },
00100     {14 ,-4 ,   0, 0 ,48 },
00101     {15 ,-3 ,   0, 0 ,64 },
00102     {16 ,-2 ,   0, 0 ,97 },
00103     {17 ,-2 ,   0, 0 ,97 },
00104     {18 ,-1 ,   0, 0 ,127},
00105     {19 ,0,     1, 0 ,0  },
00106     {20 ,0,     1, 0 ,0  },
00107     {21 ,0,     1, 0 ,0  },
00108     {22 ,1,     1, 0 ,127},
00109     {23 ,1,     1, 0 ,127},
00110     {24 ,1,     1, 0 ,127},
00111     {25 ,1,     1, 0 ,127},
00112     {26 ,1,     1, 0 ,127},
00113     {27 ,1,     1, 0 ,127},
00114     {28 ,1,     1, 0 ,127},
00115     {29 ,0,     1, 0 ,0  },
00116     {30 ,0,     1, 0 ,0  },
00117     {31 ,0,     1, 0 ,0  },
00118     {32 ,-1,    0, 0 ,127},
00119     {33 ,-2,    0, 0 ,97 },
00120     {34 ,-2,    0, 0 ,97 },
00121     {35 ,-3,    0, 0 ,64 },
00122     {36 ,-4,    0, 0 ,48 },
00123     {37 ,-5,    0, 0 ,38 },
00124     {38 ,-6,    0, 0 ,32 },
00125     {39 ,-7,    0, 0 ,27 },
00126     {40 ,-8,    0, 0 ,23 },
00127     {41 ,-9,    0, 0 ,21 },
00128     {42 ,-11 ,  0, 0 ,17 },
00129     {43 ,-12 ,  0, 0 ,15 },
00130     {44 ,-13 ,  0, 0 ,14 },
00131     {45 ,-15 ,  0, 0 ,12 },
00132     {46 ,-17 ,  0, 0 ,10 },
00133     {47 ,-18 ,  0, 0 ,10 },
00134     {48 ,-20 ,  0, 0 ,9  },
00135     {49 ,-22 ,  0, 0 ,8  },
00136     {50 ,-24 ,  0, 0 ,7  },
00137     {51 ,-26 ,  0, 0 ,7  },
00138     {52 ,-28 ,  0, 0 ,6  },
00139     {53 ,-30 ,  0, 0 ,6  },
00140     {54 ,-33 ,  0, 1 ,117},
00141     {55 ,-35 ,  0, 1 ,111},
00142     {56 ,-37 ,  0, 1 ,105},
00143     {57 ,-40 ,  0, 1 ,97 },
00144     {58 ,-43 ,  0, 1 ,90 },
00145     {59 ,-45 ,  0, 1 ,86 },
00146     {60 ,-48 ,  0, 1 ,80 },
00147     {61 ,-51 ,  0, 1 ,76 },
00148     {62 ,-54 ,  0, 1 ,71 },
00149     {63 ,-57 ,  0, 1 ,68 },
00150     {64 ,-60 ,  0, 1 ,64 },
00151     {65 ,-63 ,  0, 1 ,61 },
00152     {66 ,-66 ,  0, 1 ,58 },
00153     {67 ,-70 ,  0, 1 ,55 },
00154     {68 ,-73 ,  0, 1 ,53 },
00155     {69 ,-76 ,  0, 1 ,50 },
00156     {70 ,-80 ,  0, 1 ,48 },
00157     {71 ,-84 ,  0, 1 ,45 },
00158     {72 ,-87 ,  0, 1 ,44 },
00159     {73 ,-91 ,  0, 1 ,42 },
00160     {74 ,-95 ,  0, 1 ,40 },
00161     {75 ,-99 ,  0, 1 ,38 },
00162     {76 ,-103 , 0, 1 ,37 },
00163     {77 ,-107 , 0, 1 ,36 },
00164     {78 ,-111 , 0, 1 ,34 },
00165     {79 ,-116 , 0, 1 ,33 },
00166     {80 ,-120 , 0, 1 ,32 },
00167     {81 ,-124 , 0, 1 ,31 },
00168     {82 ,-129 , 0, 1 ,29 },
00169     {83 ,-134 , 0, 1 ,28 },
00170     {84 ,-138 , 0, 1 ,27 },
00171     {85 ,-143 , 0, 1 ,26 }
00172 };
00173 
00174 /**
00175  * \brief RTC calibration for Temperature or PPM drift
00176  */
00177 extern void RTC_ClockCalibration( Rtc* pRtc, int32_t CurrentTempr)
00178 {
00179     uint16_t i;
00180     uint32_t MR_Reg, Size;
00181   
00182     Size = sizeof(PPM_Lookup);
00183   
00184     MR_Reg = 0;
00185     for(i=0; i< Size; i++) {
00186         if(PPM_Lookup[i].Tempr == CurrentTempr) {
00187             MR_Reg |= RTC_MR_CORRECTION(PPM_Lookup[i].CORRECTION);
00188             MR_Reg |= (PPM_Lookup[i].HIGHPPM << 15);
00189             MR_Reg |= (PPM_Lookup[i].NEGPPM << 4);
00190             pRtc->RTC_MR = MR_Reg;    // update the calibration value
00191             break;
00192         }
00193     }
00194 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines