FLEXIO interrupt on KL17Z

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FLEXIO interrupt on KL17Z

653 Views
petereinramhof
Contributor I

Hi!

I'm using the KL17Z (128kB, QFN32) and I'm trying to output a signal ("one-shot PWM") via FLEXIO timer(s) on a pin.

The signal consists of a HIGH part of configurable length, e.g. 250 microseconds, followed by a LOW part of configurable length, e.g. 150 microseconds - after that the level shall be HIGH again.

The pin I'm using (PTD5) is usually multiplexed as digital I/O (ALT1), and for the purpose of outputting the signal described above, it is multiplexed as FXIO0_D5 (ALT6).

At the end of the LOW part of the signal, a UART2_FLEXIO interrupt shall be generated that disables the FLEXIO timer(s) and multiplexes the pin back to ALT1.

I tried two approached:

[1] Dual 8-bit counter PWM using Timer0

[2] Timer0 and Timer1 as 16bit counters, where Timer0 counts down (timing of the HIGH phase), triggers Timer1, which outputs the LOW phase, and at the end Timer1 shall fire an interrupt 

First, I implemented this on the FRDM-KL27Z, where it is working as intended.

On the KL17Z, which is the target hardware, THE EXACT SAME code is behaving differently. Specifically, in both cases the FLEXIO interrupt is fired only after Timer0 (Timer1) has expired (and reloaded from FLEXIO_TIMCMP0) the second time. In other words the flag TSF in FLEXIO_TIMSTAT is only set after the Timer0 (Timer1) has expired and reloaded the second, third, fourth, etc. time after enabling it, but never at the first time.

I've tried it on several instances of the target hardware, but the result is always the same - no interrupt after the first expiration/reloading of the timer on the KL17Z...

Here's the code snippet that confugers and starts FLEXIO Timer0

// Set the clock source to MCGICLK (1 MHz) - bits 23:22 = 11
SIM_SOPT2 &= ~((uint32_t)3 << 22);
SIM_SOPT2 |= (uint32_t)3 << 22;

// Enable the clock gate - bit 31 = 1
SIM_SCGC5 |= (uint32_t)1 << 31;

// Enable UART2/FLEXIO interrupts
NVIC_ISER = NVIC_ISER_UART2;

// Clear all (4) shifter status and error flags, no shifter interrupts, no shifter DMA requests
FLEXIO_SHIFTSTAT = 0x0000000F;
FLEXIO_SHIFTERR = 0x0000000F;
FLEXIO_SHIFTSIEN = 0x00000000;
FLEXIO_SHIFTEIEN = 0x00000000;
FLEXIO_SHIFTSDEN = 0x00000000;

// Set up Timer 0 - 250 microseconds HIGH, 150 microseconds LOW
FLEXIO_TIMCMP0 = ((uint32_t)149 << 8) + (uint32_t)249;
FLEXIO_TIMCFG0 = FLEXIO_TIMCFG_TIMOUT_low_on_enable_and_reset | FLEXIO_TIMCFG_TIMDEC_FlexIO_clock |
FLEXIO_TIMCFG_TIMOUT_high_on_enable_and_reset | FLEXIO_TIMCFG_TIMDIS_Never_disabled | FLEXIO_TIMCFG_TIMENA_Always_enabled |
FLEXIO_TIMCFG_TSTOP_Disabled | FLEXIO_TIMCFG_TSTART_Disabled;

// Clear all (4) timer status flags, allow timer status interrupts for Timer 0
FLEXIO_TIMSTAT = 0x0000000F;
FLEXIO_TIMIEN = 0x00000001;

// Enable the FLEXIO module (bit #0)
FLEXIO_CTRL = 0x00000001;

...

// Clear Timer0 TSF flag and start the signal generation

FLEXIO_TIMSTAT = ((uint32_t)0 << 1);
FLEXIO_TIMCTL0 = (FLEXIO_TIMCTL_TRGSRC_Internal | FLEXIO_TIMCTL_PINCFG_Output |  FLEXIO_TIMCTL_PINSEL(5) | FLEXIO_TIMCTL_PINPOL_Active_high | FLEXIO_TIMCTL_TIMOD_Dual_8b_counter_PWM);

Cheers,

Peter.

Labels (1)
0 Kudos
3 Replies

550 Views
petereinramhof
Contributor I

P.S.:

The output pin PTD5 does the following after starting Timer0 using the code snippet above:

  • HIGH for 250 microseconds
  • LOW for 150 microseconds - NO INTERRUPT
  • HIGH for 250 microseconds
  • LOW for 150 microseconds - after that a FLEXIO interrupt is fired
  • HIGH for 250 microseconds
  • LOW for 150 microseconds - FLEXIO interrupt

...

0 Kudos

550 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hi Peter,

I see that your using the FlexIO to generate a PWM, I think it will be easier to implement it with the TPM module, since the principal purpose of the FlexIO is emulated other protocols.

In the following link you can find the SDK, this contain some examples of how to use the FTM to generated a PWM.

Regarding your implementation, only to confirm the correct function of the FlexIO module in the KL17, I will suggest to check one of the FlexIO examples from the SDK (UART, I2C or SPI) and see if the interruption is triggered the first time.

Let me know your findings.

Best Regards,

Alexis Andalon

0 Kudos

550 Views
petereinramhof
Contributor I

Hi Alexis,

thanks for your feedback!

The "funny" thing is that, until recently, I had been using the TPM module (specifically TPM0_CH5) for the signal generation described in my initial post.

Due to some recent hardware changes on the PCB we are using the KL17Z on - and limited freedom of changing the layout on that PCB - I had/have no other possibility than going for FlexIO on that specific pin (PTD5).

I'm already using TPM0_CH0, TMP0_CH1 and TPM0_CH2 for controlling an RGB-LED's colour intensities, and if I understood correctly, the period of the channels of the module TPM(0) cannot be set individually, only the pulse width. The signal's period and the LED's PWM period must be configurable independently...

In the meantime I found a somewhat viable workaround for my issue:

I let Timer 0 run in 16bit counter mode, clocked by the 48MHz system clock, and I'm using both edges of its trigger output (125 kHz or 8 microsecond resolution) to clock Timer 1, which is running in 8bit PWM mode.

Interestingly, using this setup, the interrupt does fire as expected i.e. *every* time there is a reload of Timer 1.

With the resolution of 8 microseconds (I wanted 1 microsecond) and the 8bit PWM, I can configure the signal's HIGH and LOW durations to be up to 255 * 8 = 2040 microseconds (i.e. ~2ms, I wanted up to 10ms).

It's O.K. for now - the initial configuration of 250 microseconds HIGH followed by 150 microseconds LOW is now 248 HIGH and 152 LOW, which is sufficiently close - luckily it doesn't have to be microsecond-exact.

I'll keep "playing" around with the FlexIO as far as my time allows it - if I learn something new, I'll get back to this post, but for now I guess it's best to mark my question assumed answered.

Cheers,

Peter.

0 Kudos