Hi Jesper,
ATCR[PINPER] is not supported on all Kinetis family, it has not effect on the pin if enabled. Also, when using Time control (TCSR, TCCR), ATCR[PEREN] is not required and not supported.
To achieve 200ms low and 800ms high:
1. Use external 50 MHz instead of internal core/system clock (which you have already done it) to get accuracy period.
2. ATPER set to 1s (0x3B9aCA00)
3. TCCRn set to 200ms (0x0BEBC200)
4. TCSRn set to mode 7 (clear) and Timer interrupt enable
5. Enable the timer
In interrupt 1588 interrupt service handler:
- Clear Timer flag
- alternating two counters (0/1) for 800ms and 200ms
- clear mode
- set desired timer to TCCRn
- set desired mode
- restart timer
example:
void fec1588_isr(void)
{
if (ENET_TGSR & ENET_TGSR_TF2_MASK)
{
ENET_TCSR2 |= ENET_TCSR_TF_MASK;
if (count == 0)
{
ENET_TCSR2 &= ~ENET_TCSR_TMODE_MASK;
ENET_TCCR2 = 800000000;
ENET_TCSR2 |= ENET_TCSR_TMODE(6);
ENET_ATCR |= ENET_ATCR_RESTART_MASK;
count++;
}
else
{
ENET_TCSR2 &= ~ENET_TCSR_TMODE_MASK;
ENET_TCCR2 = 200000000;
ENET_TCSR2 |= ENET_TCSR_TMODE(7);
ENET_ATCR |= ENET_ATCR_RESTART_MASK;
count = 0;
}
}
}
void main(void)
{
PORTC_PCR18 = PORT_PCR_MUX(4)|PORT_PCR_PE_MASK|PORT_PCR_PS_MASK;
SIM_SCGC2 |= 1;
ENET_EIMR =ENET_EIMR_TS_TIMER_MASK;
enable_irq(98 - 16);
count = 0;
OSC_CR |= OSC_CR_ERCLKEN_MASK;//Enable OSCERCLK
SIM_SOPT2 = SIM_SOPT2_TIMESRC(2);
ENET_ECR |= ENET_ECR_ETHEREN_MASK | ENET_ECR_EN1588_MASK;
ENET_ATPER = 0x3B9ACA00; //10^9
ENET_ATINC = ENET_ATINC_INC(20) | ENET_ATINC_INC_CORR(20);
ENET_TCCR2 = 200000000;
ENET_TCSR2 = ENET_TCSR_TMODE(7) | ENET_TCSR_TIE_MASK;
ENET_ATCR |= ENET_ATCR_EN_MASK;
}
If restart timer is not asserted, the timer will continue to run and changing the TMODE will have incorrect result from the output.
Another approach is to set ATPER to 200ms, then use the timer interrupt to toggle high or low depends on counts.
Bets Regards
Mario