HCS08 TPM Configured for Quadrature Decoding?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

HCS08 TPM Configured for Quadrature Decoding?

1,960 次查看
windpower
Contributor I
Hi,
 
I have used Freescale's 32 bit processors with TPU functions, which make quadrature decoding straightforward.  I am looking at the HCS08 family, which has a TPM.  Can this be configured for quadrature counting?
 
Thanks for the response.
 
Alan
标签 (1)
0 项奖励
回复
2 回复数

517 次查看
mayfly
Contributor III
Hi Alan,

I have implemented the tpm in a MC9S08DZ60 for capturing quadrature encoder pulses.  Relevant parts of my code are listed below.  Note that in order to determine direction, my code only captures one channel and looks at the status of the other channel.   You can get a higher resolution using both channels and watching both the rising and the falling edges, but it will cost you cpu cycles to do so (I had to do it this way to accomodate for a higher resolution encoder on a faster motor).   Hope it helps.
Code:
void MCU_init_tpm1(void){  //Initialize timer TPM1 channel, assumes not touched since reset!  TPM1SC_CLKSA = 1;//Select BUS clock  TPM1SC_CLKSB = 0;  TPM1SC_PS = T1PRESCALAR;//clock source divided by prescalar  TPM1MOD = T1MODULUS;//set Counter modulus  TPM1SC_CPWMS = 0;   // not center aligned    //TPM1, channel 1  TPM1C1SC_MS1B = 0;  // MS0B:MS0A 00 == input capture  TPM1C1SC_MS1A = 0;  //  TPM1C1SC_ELS1B = 0; // ELSnB:ELSnA 01 == rising edge capture only (10 falling, 11 either)  TPM1C1SC_ELS1A = 1; // 0 = Select high as true, 1 = Select low as true    TPM1C1SC_CH1IE = 1;  TPM1C1SC = TPM1C1SC;  TPM1SC_TOIE = 1;  //enable timer overflow for counter //Verify!!! FIX ME!!! RPO}void update_encoder(unsigned char direction_verify_channel){   if(!direction_verify_channel)    //   {      if(!++encoder[2]) if(!++encoder[1]) encoder[0]++; //"up" //encoder uses 3 bytes, shift the carry bit up/down   }   else   {      if(!encoder[2]--) if(!encoder[1]--) encoder[0]--; //"down"   }}void interrupt 6 tpm1ch1_ChannelA_inputcapture(void){   unsigned char dummy = 0;   dummy = TPM1SC;   update_encoder(ChannelB);   TPM1SC &= 0x7F;   update_speed();   dummy = TPM1C1SC_CH1F;   TPM1C1SC_CH1F = 0;}

 




0 项奖励
回复

517 次查看
bigmac
Specialist III
Hello Alan,
 
I am not familiar with the capabilities of the TPU module.  However, a search of the forum revealed the following lengthy thread from some time ago, in which a number of approaches to quadrature decoder signal processing were discussed.
 
The complexity is likely to depend on the type of decoder, optical or contact, and indent or no indent, and the purpose of the control.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-03-11 05:03 PM
0 项奖励
回复