Basic FTM settings

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

Basic FTM settings

Jump to solution
919 Views
tomášpilný
Contributor I

Hello everybody,

 

I am new to this forum and I've just started with kinetis, so please try to keep that in mind.

I am using MK60N512VMD100 on custom board, with CW v10.6.

 

First I'll try to explain my aim - I am trying to write simple application for Ultrasonic Ranging Module HC - SR04.

The module needs to be triggered by 10 micro second pulse, then it outputs pulse with range in proportion (the time it took for sound wave to travel from module, to measured object and back).

I want to have, lets say, 7 modules, fairly close together, but I want to detect object (hand) only for one of the modules.

 

So what I need is to set FTM to generate one pulse on one pin, and then measure the echo signal on another pin. This all is to be repeated for another module, on another pin. I think that the trigger signal could be the same for all modules, but I would be measuring only one of them at a time (to avoid capturing echo from different module.)

 

I've been trying to learn the correct setting from Reference Manual and tons of post all around the internet - without luck.

Now for the code. For start I'm trying to do the 10us pulse. The idea is to use edge aligned PWM, high-true pulses, clear on match. When the counter (CNT) reaches the modulo value (MOD) I catch the interrupt and disable the FTM. I'm not realy sure if it is the best way, or even if it leads to my destination

 

The biggest problem now is that the program crashes at line FTM0_SC |= FTM_SC_CLKS(0x01) | FTM_SC_TOIE_MASK;

When I run it full speed without breakpoints or I step through it just stops executing. When I hit the Suspend button I get "Target request failerd: ARM GDI Protocol Adapter : Stop failed. Non Fatal Error."

 

Do you have any ideas where the problem might be?

 

Thanks in advance

Tom

Original Attachment has been moved to: main.c.zip

0 Kudos
1 Solution
637 Views
egoodii
Senior Contributor III

Obviously it is your attempt to change SIM_CLKDIV1 'on the fly'.  Don't do that -- use the FTM prescaler.  There are 'procedures' required to change clocks, and if you truly need a different frequency I would change it back at the initial setup.  In any case, this particular statement also forgets to 'clear out' the OLD divider before 'ORing in' the new.

It LOOKS like the 'next line' is the trouble because the CPU is pipelined, and has 'write buffering'.  In a more advanced processor like this, you have to get used to 'several things going on at a time' in your instruction stream.

View solution in original post

0 Kudos
2 Replies
638 Views
egoodii
Senior Contributor III

Obviously it is your attempt to change SIM_CLKDIV1 'on the fly'.  Don't do that -- use the FTM prescaler.  There are 'procedures' required to change clocks, and if you truly need a different frequency I would change it back at the initial setup.  In any case, this particular statement also forgets to 'clear out' the OLD divider before 'ORing in' the new.

It LOOKS like the 'next line' is the trouble because the CPU is pipelined, and has 'write buffering'.  In a more advanced processor like this, you have to get used to 'several things going on at a time' in your instruction stream.

0 Kudos
637 Views
tomášpilný
Contributor I

Thanks for fast respond. I've removed the attempt to change system clock. Now it seem to be working properly.

0 Kudos