encCtrl.c

Go to the documentation of this file.
00001 
00010 #include <7040S.H>
00011 #include "encCtrl.h"
00012 
00013 
00019 void initEnc(void) {
00020   MTU1.TMDR.BYTE = 0xc4;        /* encoder mode 1 */
00021   MTU2.TMDR.BYTE = 0xc4;        /* encoder mode 1 */
00022   MTU.TSTR.BYTE |= 0x06;        /* start count up */
00023 
00024   PFC.PECR2.WORD |= 0x1100;     /* TIOC1A, TIOC2A */
00025   MTU1.TIOR.BYTE = 0x0a;        /* input capture */
00026   MTU2.TIOR.BYTE = 0x0a;        /* input capture */
00027 
00028   PFC.PEIOR.WORD &= ~0x0050;    /* use TIOC1A, TIOC2A port */
00029 
00030   PFC.PACRL2.WORD &= ~0xf000;   /* TCLKA, TCLKB */
00031   PFC.PACRL2.WORD |= 0x5000;
00032   PFC.PACRL1.WORD &= ~0x000f;   /* TCLKC, TCLKD */
00033   PFC.PACRL1.WORD |= 0x0005;
00034 
00035   MTU1.TCNT = 0;                /* counter=0 */
00036   MTU2.TCNT = 0;
00037   MTU1.TGRA = 0;                /* buffer=0 */
00038   MTU2.TGRA = 0;
00039 }
00040 
00041 
00050 static unsigned short getEncValue(const unsigned char id) {
00051   unsigned short cnt = -1;
00052 
00053   if (id == 0) {
00054     cnt = MTU1.TGRA;
00055   } else if (id == 1) {
00056     cnt = MTU2.TGRA;
00057   }
00058   return cnt;
00059 }
00060 
00061 
00070 void initEncInfo(const unsigned char id, encInfo_t *enc) {
00071   enc->prev = getEncValue(id);
00072   enc->id = id;
00073   enc->enc_direction = ENC_CW_TO_PLUSE;
00074   enc->diff = 0;
00075   enc->total = 0;
00076 }
00077 
00078 
00088 void updateEncDiff(encInfo_t *enc) {
00089 
00090   short now = getEncValue(enc->id);
00091   enc->diff = enc->enc_direction * (now - enc->prev);
00092   enc->total += enc->diff;
00093   enc->prev = now;
00094 }
00095 
00096 
00105 int getEncDiff(encInfo_t *enc) {
00106   return enc->diff;
00107 }
00108 

Generated on Mon Apr 13 22:52:04 2009 by  doxygen 1.5.7.1