Daniel Phillips

Quadrature Decoder on 56F8037 best option?

Discussion created by Daniel Phillips on Sep 14, 2010
Latest reply on Sep 30, 2010 by giacomopetrini

Hello.

 

I am trying to get a MC56F8037 to read a Quadrature encoder. It is difficult as the last embedded platform I programmed on  an open loop V/Hz Induction motor speed control on a . . .9S12C  . . . is different to the DSP architecture of the 56F8037 . I have 2 questions.

 

1. I tried writing the code to do the quadrature encoding by myself. But it did not work. Should I attempt to use the stationery code in processor expert? Like in this post? https://community.freescale.com/message/47553#47553 .  Or does someone think that my code is close to working?

 

2. I have noticed that you cannot write to some registers in the 56F8037 using the assignment operator ' = ' in C. (I get an lvalue error). This is different from the 9S12 why is this so?. I believe in the code snippet provided I am using an assembly move instruction to write to the register, as this is how the examples in codewarrior worked. Is there a document aimed at HC12/9S12 programmers transitioning to the 56F8XXX type DSC's?

 

Here is the code, as best as I can currently interpret the Peripheral description and System Intergration Module documents.

 

#include <stdlib.h>
#include <stdio.h>
#include "MC56F802x3x.h"


int main(void)
{
 /* DISABLE COP TIMER */
 asm(bfclr #$FFFF,X:COP_CTRL);
 
  //initialise quadrature encoder
 asm (move.w #$8020,X:smileyfrustrated:IM_GPSA0); //Bit 6=1 (Timer A0 ON GPIOA6) and Bit 12=1 (Timer A1 on GPIOA12)
 asm (move.w #$1000,X:smileyfrustrated:IM_GPSA0);  //Bit 12=1 (Timer A0)
 asm (move.w #$0100,X:smileyfrustrated:IM_GPSA1);  //Bits 9-8 = 10 (Timer A1)
 asm (move.w #$0080,X:TMRA0_CTRL);  //0x0080
 asm (move.w #$0000,X:TMRA0_SCTRL);  //0x0000
 asm (move.w #$0000,X:TMRA0_CNTR); //0x0000 
 asm (move.w #$0000,X:TMRA0_LOAD); //0x0000 
 asm (move.w #$FFFF,X:TMRA0_COMP1); //0xFFFF
 asm (move.w #$0000,X:TMRA0_COMP2); //0x0000
 asm (move.w #$0000,X:TMRA0_CSCTRL); //0x0000
 asm (move.w #$8080,X:TMRA0_CTRL); //0x8080
 
 while (1)
 {
  asm(nop);
  asm(nop);
  asm(nop);
  asm(nop);
  asm(nop);
  printf("Value of Quadrature Decoder:%u",TMRA0_CNTR);  //very large function will not be present after debugging
  asm(nop);
 }
 
}

 

Im expecting inputs are on Pins A6 and A12. And the count value appears in TMRA0_CNTR up or down counting depending on direction.

 

Thanks for a reply in advance.

Outcomes