Matt,
Here is a simple code snippet that demonstrates setting up quadrature decoding:
/* New Thread entry function */
#include "new_thread.h"
#include "../synergy/ssp/src/driver/r_gpt/hw/hw_gpt_private.h"
volatile uint32_t Encoder_1;
volatile uint32_t Encoder_2;
void SetupGPT_Encoders(uint8_t channel);
/*
Encoder 1
A1 129 P1_3 GTIOC2A
B1 130 P1_2 GTIOC2B
Z1 132 P1_0 GTETRGA
Encoder 2
A2 125 P1_7 GTIOC8A
B2 126 P1_6 GTIOC8B
Z2 128 P1_4 GTETRGB
*/
void SetupGPT_Encoders(uint8_t channel)
{
HW_GPT_PowerOn(channel);
GPT_CH(channel).GTUPSR = 0x6900; // Phase counting mode 1
GPT_CH(channel).GTDNSR = 0x9600; // Phase counting mode 1
GPT_CH(channel).GTCNT = 0; // Reset Count
GPT_CH(channel).GTCR_b.CST = 1; // Start Counter
}
void new_thread_entry(void)
{
SetupGPT_Encoders(2);
SetupGPT_Encoders(8);
while (1)
{
tx_thread_sleep (1);
Encoder_1 = GPT_CH(2).GTCNT;
Encoder_2 = GPT_CH(8).GTCNT;
}
}
-Gary