SAMV71 Xplained Ultra Software Package 1.5

rtc_calib.c

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