Pololu Qik 2s9v1 Manuel d'utilisateur Page 21

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 24
  • Table des matières
  • DEPANNAGE
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 20
Steps 3, 4, & 5:
_______________________________________________
1 0 0 0 1 0 0 1 ) 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
XOR 1 0 0 0 1 0 0 1 | | | | | | | | | | | | | | |
--------------- | | | | | | | | | | | | | | |
1 0 0 1 0 0 0 1 | | | | | | | | | | | | | |
shift ----> 1 0 0 0 1 0 0 1 | | | | | | | | | | | | | |
_______________ | | | | | | | | | | | | | |
1 1 0 0 0 0 0 0 | | | | | | | | | | |
1 0 0 0 1 0 0 1 | | | | | | | | | | |
_______________ | | | | | | | | | | |
1 0 0 1 0 0 1 0 | | | | | | | | | |
1 0 0 0 1 0 0 1 | | | | | | | | | |
_______________ | | | | | | | | | |
1 1 0 1 1 0 0 0 | | | | | | |
1 0 0 0 1 0 0 1 | | | | | | |
_______________ | | | | | | |
1 0 1 0 0 0 1 0 | | | | | |
1 0 0 0 1 0 0 1 | | | | | |
_______________ | | | | | |
1 0 1 0 1 1 0 0 | | | |
1 0 0 0 1 0 0 1 | | | |
_______________ | | | |
1 0 0 1 0 1 0 0 | |
1 0 0 0 1 0 0 1 | |
_______________ | |
1 1 1 0 1 0 0 = 0x17
So the full command packet we would send to retrieve the PWM configuration parameter with CRC enabled is:
0x83, 0x01, 0x17
There are some tricks you can use in your programs to make the CRC calculation much faster. You can find an
example of this Section 6.a.
6.a. CRC Computation in C
The following example program shows how to compute a CRC in the C language. The idea is that the CRC of
every possible byte is stored in a lookup table, so that it can be quickly loaded when computing the CRC of a
longer message. The individual CRC bytes are XORed together with the C operator ^ to get the final CRC of the
message. In the example main() routine, this is applied to generate the CRC byte in the message 0x83, 0x01, that
was used in Section 6.
#include <stdio.h>
const unsigned char CRC7_POLY = 0x91;
unsigned char CRCTable[256];
unsigned char GetCRC(unsigned char val)
{
unsigned char j;
for (j = 0; j < 8; j++)
{
if (val & 1)
val ^= CRC7_POLY;
val >>= 1;
}
return val;
}
void GenerateCRCTable()
{
int i, j;
// generate a table value for all 256 possible byte values
for (i = 0; i < 256; i++)
{
CRCTable[i] = GetCRC(i);
}
Qik 2s9v1 User's Guide © 2001–2012 Pololu Corporation
6. Cyclic Redundancy Check (CRC) Error Detection Page 21 of 24
Vue de la page 20
1 2 ... 16 17 18 19 20 21 22 23 24

Commentaires sur ces manuels

Pas de commentaire