智能车制作

标题: 同时多通道视波 [打印本页]

作者: juliaレ葛    时间: 2012-6-19 09:51
标题: 同时多通道视波
Data send adapt CRC16 verification,The following is the function of CRC16,please refer
//-------------------------------------------------------------------------------------------
unsigned short CRC_CHECK(unsigned char *Buf, unsigned char CRC_CNT)
{
    unsigned short CRC_Temp;
    unsigned char i,j;
    CRC_Temp = 0xffff;
    for (i=0;i<CRC_CNT; i++){      
        CRC_Temp ^= Buf;
        for (j=0;j<8;j++) {
            if (CRC_Temp & 0x01)
                CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001;
            else
                CRC_Temp = CRC_Temp >> 1;
        }
    }
    return(CRC_Temp);
}
//-------------------------------------------------------------------------------------------
The data from computer to MPU is like this:
Ch1_Addr_LL,Ch1_Addr_LH,
Ch1_Addr_HL,Ch1_Addr_HH,
Ch2_Addr_LL,Ch2_Addr_LH,
Ch2_Addr_HL,Ch2_Addr_HH,
Ch3_Addr_LL,Ch3_Addr_LH,
Ch3_Addr_HL,Ch3_Addr_HH,
Ch4_Addr_LL,Ch4_Addr_LH,
Ch4_Addr_HL,Ch4_Addr_HH,
CRC16_L,CRC16_H
//-------------------------------------------------------------------------------------------
The data from MPU to computer should be like this:
Ch1Data_L,Ch1Data_H,
Ch2Data_L,Ch2Data_H,
Ch3Data_L,Ch3Data_H,
Ch4Data_L,Ch4Data_H,
CRC16_L,CRC16_H

//-------------------------------------------------------------------------------------------
the following is MPU code,please refer.
//-------------------------------------------------------------------------------------------
#define RxCountMax 18
unsigned short RxBuf[RxCountMax];
unsigned short TxBuf[10];
unsigned short RxCnt;
unsigned short TxCnt;
unsigned short Rx50msCnt;
unsigned long pAddr1,pAddr2,pAddr3,pAddr4;
//Receive interrupt routine
void voRxIsr(void)
{
unsigned short i,CRC_RX,CRC_Tmp;
RxBuf[RxCnt] = Rx.data;    //acquire data
RxCnt++;
        
if(RxCnt == RxCountMax) {
  CRC_Tmp =  CRC_CHECK(RxBuf,16);   //CRC Calculation
  CRC_RX = ((unsigned short)RxBuf[RxCountMax-1]<<8) + RxBuf[RxCountMax-2];
  if(CRC_Tmp == CRC_RX){
   pAddr1 = ((ULONG)(RxBuf[0x3])<<24)|((ULONG)(RxBuf[0x2])<<16)|((ULONG)(RxBuf[0x1])<<8)|RxBuf[0x0];
   pAddr2 = ((ULONG)(RxBuf[0x7])<<24)|((ULONG)(RxBuf[0x6])<<16)|((ULONG)(RxBuf[0x5])<<8)|RxBuf[0x4];
   pAddr3 = ((ULONG)(RxBuf[0xB])<<24)|((ULONG)(RxBuf[0xA])<<16)|((ULONG)(RxBuf[0x9])<<8)|RxBuf[0x8];
   pAddr4 = ((ULONG)(RxBuf[0xF])<<24)|((ULONG)(RxBuf[0xE])<<16)|((ULONG)(RxBuf[0xD])<<8)|RxBuf[0xC];  
  }
  RxCnt = 0;  
}
Rx50msCnt = 0;
        //to add--Clear Receive Data Register Fll flag; //clear Receive Data Register Full flag
}
//-------------------------------------------------------------------------------------------
//Transfer interrupt routine
void voTxIsr(void)
{
     if(TxCnt <= 9){
  Tx.Register = TxBuf[TxCnt];
  //Clear Tx interrupt flag
  TxCnt++;
  if(TxCnt >= 10){
   //send interrupt disable  
  }
     }
}
//-------------------------------------------------------------------------------------------
//Monitor routine Execute every T Period time
void voMonitor(void)
{
unsigned short ChxData[4],CRC_Tmp,i;
Rx50msCnt++;
if(Rx50msCnt >=500) {
  RxCnt = 0;
  Rx50msCnt = 0;
}

ChxData[0].sw = *(unsigned short *)pAddr1;
ChxData[1].sw = *(unsigned short *)pAddr2;
ChxData[2].sw = *(unsigned short *)pAddr3;  
ChxData[3].sw = *(unsigned short *)pAddr4;

for(i=0;i<4;i++){   
  TxBuf[2*i+0] = ChxData.sb.low;  // ch low byte
  TxBuf[2*i+1] = ChxData.sb.hi;   // ch hi byte
}

CRC_Tmp = CRC_CHECK(TxBuf,8);
TxBuf[8] = CRC_Tmp&0xff;
TxBuf[9] = CRC_Tmp>>8;
//send first data
Tx.Register = TxBuf[0];    //send begin
//Enalbe TXD interrupt
TxCnt = 1;
}
//-------------------------------------------------------------------------------------------
谁能解释一下,还有具体怎么用,要那种能四个通道看到波形的。菜鸟级别求解释清楚点。一个人做车不容易啊,贡献也就这么多了。求大神求给力。
作者: juliaレ葛    时间: 2012-6-19 09:53
我看了什么crc16检验错误,但没看懂,不要理论,只求能用,能看波形





欢迎光临 智能车制作 (http://111.231.132.190/) Powered by Discuz! X3.2