Before I start answering the many questions, I'd like to mention Teensy has a feature called DMA. It's complex to use, but it'll be well worth the trouble to learn.
Now, about some of those specific questions....
During the cycle the on and off time changes for this reason I think I can't use a simple analogwrite.
You can use analogWrite, but you'll need to do it within every PWM cycle. The PWM is double buffered, so no matter where in the cycle you write, the current cycle completes with the prior setting and the next cycle begins with the setting you wrote during the prior cycle.
I read the datasheet but I don't know how to access to the timers and change the prescaler, read the "overflow" flag and change the correct register to switch the state of a pin.
I don't understand why you're asking to "the correct register to switch the state of a pin". You don't directly manipulate the pin. The timer control the pin. You write a number to the timer channel register. The timer drives the pin high at the beginning of the cycle, the moment it rolls back to zero. Then the pin is driven low later in the cycle, when the timer increments to whatever number you put into the register. When using PWM you don't ever control the pin directly.
In the
MK20DX256 reference manual, these timer registers are documented in chapter 36, starting on page 769.
The prescaler setting and overflow flag are in the FTM0_SC register, section 36.3.3 starting on page 780. The register that controls how far the timer counts is FTM0_MOD on page 782.
The timer has 8 channels, so it can create 8 PWM signals related to the same timer. Each channel is controlled by a config register and a value register, which are documented on pages 783 to 786.
The microchip pics worked at 16/64 MHz (250/62,5 ns per instruction), how long is an instruction on this teensy?
By default Teensy 3.2 runs at 96 MHz. Most instructions execute in a single cycle, or 10.42 ns. However, sometimes 2 or more cycles are needed, for a variety of reasons.
It's probably also worth mentioning the timers run from a slower clock, usually 48 or 60 MHz. The achievable PWM resolution is related to this F_BUS clock speed.
The pulses lasts around 70 microseconds on and 350 microseconds off, after that again on around 140 us and 280 off ....
....
The on and off time is changing and this time is very short and the transition between theses pulses must be less than 500ns. We wrote the code in asm because it was impossible with low cost microchip pics in C.
My question is it possible to do this with teensy in C or I have to use registers and flags?
It's definitely possible to do with Teensy 3.x using only C / C++ programming.
I do not recommend trying to write a tight loop to poll the hardware, as you'd do on a PIC. Teensy is far more powerful, and you can use that power to do things very easily in ways that are easier to maintain and won't break when you make minor changes to the code.
The simpler way would involve using an interrupt from the TOF (timer overflow) bit in FTM0_SC. To do this, you'd attachInterruptVector to put your function into the interrupt table, then set TOIE and use NVIC_ENABLE_IRQ to turn on the interrupt. Then your function will run every time the timer overflows. Just write the next 6 numbers in the 6 PWM channel value registers.
The more advanced way would be to configure 6 DMA channels (or perhaps just 1 with tricky minor loop settings) to copy the numbers from a big buffer in memory automatically do the channel value registers, triggered every time the overflow bit occurs. Sadly, on Teensy 3.1 & 3.2, there isn't a TOF DMA trigger. Teensy 3.6 has this, so the best path might be to go right to 3.6.
To to this on Teensy 3.2, you'd have to dedicate one of the 8 timer channels to a minimum width PWM pulse. Then that channel could trigger the DMA, which would write to 6 of the other 7 channels.
You can set the DMA up to repeat automatically, so it will just keep copying the memory buffer to the PWM channels automatically. Then your program doesn't need to do anything at all. You can just sit back and let the DMA do all the fast data movement, and of course rewrite the numbers in buffer if you want to change the waveform.
Steps from 19 to 36 have the same times but backwards and from 5,000us to 10,000us this mosfet must be off and later start again the step 1.
Freescale actually packed the timer's PWM with tons of awesome features, for just the sort of thing you're trying to do. Pairs of PWM can be controlled together with programmable dead time. But it's a lot of complex settings.
For this reason I need 6 independent timers for switching on/off 6 pins of the microcontroller and generate the set of pulses for each mosfet at the same time. I hope you know what I'm trying to explain.
Yes, I understand. It looks like pretty standard 3 phase power synthesis.
You don't use 6 independent timers. You use 1 timer with 6 independent channels that all work from the same time base. The FTM timer is designed to do exactly what you want.
With the Microchip Pics we did only 3 steps to control the motor but I think Teensy can do it with more levels
I believe you'll be amazed what Teensy can do for you, if you leverage the DMA channels. It's probably capable of much faster than your mosfet driver circuitry can handle.
I don't have time to get into the details right now, but I'll mention the audio library has a PWM output that outputs a 88.2 kHz PWM signal and every cycle is controlled by 2 copies of each audio sample. Maybe take a look at that code....