Below is the code for what i am trying to acheive..The problem i am having is i see all the compare evnts happen to be at the same time. for example in OC3-init() if i am waiting for OC3 event all the other events happen at that time. and if i am waiting for OC6 event all the other events happen with OC6. Can you guys let me know what am i doing wrong?
void main(void)
{
TOF_init();
MODRR = 0x00; //set port T as timer outputs
DDRT = 0xFF;
PTT = 0x50;
EnableInterrupts;
for(;

{
}
}
void TOF_init(void)
{
TSCR1 = 0x80; // Enable TCNT, 4MHz in run mode
TSCR2 = 0x80; // TCNT prescale, TOI arm
/* Bottom three bits of TSCR2 (PR2,PR1,PR0) determine TCNT period
divide BootMode(24MHz) Run Mode (4MHz)
000 1 42ns TOF 2.73ms 250ns TOF 16.384ms
001 2 84ns TOF 5.46ms 500ns TOF 32.768ms
010 4 167ns TOF 10.9ms 1us TOF 65.536ms
011 8 333ns TOF 21.8ms 2us TOF 131.072ms
100 16 667ns TOF 43.7ms 4us TOF 262.144ns
101 32 1.33us TOF 87.4ms 8us TOF 524.288ms
110 64 2.67us TOF 174.8ms 16us TOF 1.048576s
111 128 5.33us TOF 349.5ms 32us TOF 2.097152s */
TFLG2 = 0x80; // initially clear TOF
usTimer31to16 = 0;
}
__interrupt void TOF_Interrupt(void)
{
usTimer31to16++;
if (usTimer31to16 == 0xFFFF)
{
usTimer31to16 = 0;
}
if (usTimer31to16 == 2)
{
usTimer31to16 = 0;
acquire_data();
}
TFLG2 = 0x80; // acknowledge TOF
}
void OC3_Init(void)
{
unsigned short usTCNT;
PTT = (PTT | 0x01);
TFLG1 = 0x78; // clear timer capture interrupt register
// TSCR1 = 0x00; //timer disable
TIOS |= 0x78; // activate TC6->3 as output compare
TSCR2 = 0x00; // TCNT prescale, Disable Timer overflow interrupt
TIE |= 0x78;
// C6 C5 C4 C3
// 1 0 1 1 1 0 1 1
// LOW HIGH LOW HIGH
TCTL1 = 0x2E; //change state OC 6-4
TCTL2 = 0xC0; //change state OC 3
//get the current TCNT
usTCNT = TCNT;
//setup the waveform to start sometime in the future
TC3 = usTCNT + 100;
TC4 = usTCNT + 105;
TC5 = usTCNT + 700;
TC6 = usTCNT + 1100;
// TSCR1 = 0x80; //timer enable
while(!(TFLG1 & 0x40))
{
}
TFLG1 = 0x78; // clear timer capture interrupt register
TSCR2 = 0x80; // enable Timer overflow interrupt
PTT = (PTT & 0x01);
}
void acquire_data(void)
{
DisableInterrupts;
OC3_Init(); //enables timer for output compare mode
TIOS =0x00; //disable out put compare
PTT = 0x50;
EnableInterrupts;
}
Thanks!!!!!!!!!