Hello,
I am facing an odd problem with the general purpose timer setup of the TMS320F2812. The code below initializes some timer registers and the device outputs a square wave. Everything works as expected. But this is not the case when the bits of the input clock prescaler (TPS) are changed to a value other than 0. If TPS=1 I expect the period to be double since the input clock is divided by 2, and so forth for higher values in TPS. However the signal is constantly low if TPS in not zero; no signal appears at all.
With the code as it is below, the register T1CON is set to 0x1042. If one suspends the emulation and sets the register to 0x1142 (everything the same except with TPS=1) it works. The waveform appears with twice the period. On the other hand, if TPS is set to 1 in the code, nothing changes when one sets it from 0x1142 to 0x1042 when the emulation is suspended.
Why does this behaviour occur?
Regards,
Adrian
/*
* timertry_T1PWM
* main.c
*
* use the GP timer compare unit of event manager A, timer 1
* GP timer 1 uses its own compare functionality (output T1PWM)
* output pin: T1PWM (pin 15)
*
*/
#include "DSP281x_Device.h"
#include "math.h"
void main() {
float d=0.77;
InitSysCtrl();
// configure pins as peripheral (here: timer) outputs (as compared to general digital I/O)
EALLOW;
GpioMuxRegs.GPAMUX.all=0x40; // T1PWM pin, 6th bit
EDIS;
// GP timer 1 setup
EvaRegs.T1CON.bit.FREE=0; // stop immediately on emulation suspend
EvaRegs.T1CON.bit.SOFT=0; // ... second part of it
EvaRegs.T1CON.bit.TMODE=2; // continuous up-counting mode
EvaRegs.T1CON.bit.TPS=0; // input clock prescaler, corresponds to factor 1
EvaRegs.T1CON.bit.TENABLE=1; // enable timer
EvaRegs.T1CON.bit.TCLKS10=0; // use HSPCLK as clock
EvaRegs.T1CON.bit.TCLD10=0; // reload compare register T1CMPR at beginning of switching period
EvaRegs.T1CON.bit.TECMPR=1; // enable timer compare
EvaRegs.T1PR=7499; // period register = 150MHz/20kHz-1 (HISPCP = 1, TPS = 0)
// 16 bit register, max. value: 2^16-1 = 65,535
EvaRegs.T1CMPR=floor(EvaRegs.T1PR*d); // compare register for T1PWM
EvaRegs.T1CNT=0; // initialize counter register
// GP timer control register of EVA (for T1PWM)
EvaRegs.GPTCONA.bit.T1CTRIPE=0; // disable trip function that can drive output to high Z
EvaRegs.GPTCONA.bit.TCMPOE=1; // enable compare output
EvaRegs.GPTCONA.bit.T1TOADC=0; // don't set off ADC
EvaRegs.GPTCONA.bit.TCMPOE=1; // enable timer compare outputs
EvaRegs.GPTCONA.bit.T1CMPOE=1; // enable timer 1 compare outputs
EvaRegs.GPTCONA.bit.T1PIN=1; // polarity of T1PWM (1 = active L, 2 = active H)
while(1){
;
}
}