Xmega Application Note | |||||
Go to the source code of this file.
Functions | |
void | generate_qdec_signal (PORT_t *qPort, uint8_t lineCount, uint8_t freq, bool dir) |
Initializes TCE0 to create Qadrature signal. |
void generate_qdec_signal | ( | PORT_t * | qPort, | |
uint8_t | lineCount, | |||
uint8_t | freq, | |||
bool | dir | |||
) |
Initializes TCE0 to create Qadrature signal.
Calculates the values to create a Quadrature signal that has a frequency given from the freq parameter.
qPort | The port to set the signal out on. | |
lineCount | The number of lines in the Quadrature encoder. | |
freq | The frequency that is put out, (time between index signal/one rotation). | |
dir | The direction of the signal to be generated, clockwise or counterclockwise signal. |
Definition at line 95 of file qdec_signal_generator.c.
References F_CPU, q_test_sig_Port, and test_lineCount.
Referenced by main().
00096 { 00097 uint16_t ticks, quarter, half_quarter; 00098 00099 /* The following code calculates the upper boundary of the timer and the 00100 * interrupt positions to get a correct Quadrature signal of the given frequency. 00101 * 00102 * The different compare interrupts sets the phase0 and phase90 signals. 00103 * Compare A interrupt sets phase0 and clears phase90 00104 * Compare B interrupt sets phase0 and phase90 00105 * Compare C interrupt clears phase0 and sets phase90 00106 * Compare D interrupt clears phase0 and phase90. 00107 * 00108 * Ccompare A interrupt also sets the index signal when one round has passed. 00109 */ 00110 00111 /* Calculates upper boundary of timer to get desired frequency.*/ 00112 ticks = F_CPU / (freq * lineCount); 00113 quarter = ticks/4; 00114 half_quarter = ticks/8; 00115 00116 if(dir == 1){ 00117 TCE0.CCA = half_quarter; 00118 TCE0.CCB = half_quarter+quarter; 00119 TCE0.CCC = half_quarter+(2*quarter); 00120 TCE0.CCD = half_quarter+(3*quarter); 00121 }else{ 00122 TCE0.CCA = half_quarter+(3*quarter); 00123 TCE0.CCB = half_quarter+(2*quarter); 00124 TCE0.CCC = half_quarter+quarter; 00125 TCE0.CCD = half_quarter; 00126 } 00127 00128 TCE0.PER = ticks; 00129 TCE0.CTRLA = TC_CLKSEL_DIV1_gc; 00130 00131 /* Enable low level interrupt on CCA, CCB, CCC and CCD.*/ 00132 TCE0.INTCTRLB = TC0_CCAINTLVL0_bm | TC0_CCBINTLVL0_bm | 00133 TC0_CCCINTLVL0_bm | TC0_CCDINTLVL0_bm; 00134 TCC0.INTCTRLA = TC0_ERRINTLVL0_bm; 00135 00136 qPort->DIRSET = 0xFF; 00137 q_test_sig_Port = qPort; 00138 00139 test_lineCount = lineCount; 00140 }
Generated on Wed Jul 30 09:22:38 2008 for AVR1600 Using the XMEGA Quadrature Decoder by ![]() |