How to set main core frequency of FRDM-K22F to 100MHz?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to set main core frequency of FRDM-K22F to 100MHz?

10,512件の閲覧回数
zoranm
Contributor III

Hello all. I am working on this ARM Cortex M4 board and as you can see the MCU runs at 120 MHz. I would like to bring that down to 100 MHz because I am trying to implement a Timer init function and interrupt handler. A basic 1ms heartbeat timer is needed for much of the testing I need to do regarding this board. I found this reference manual for the specific MCU on this board. I've been told I could alter the clock going into the systick or alter the PLL configuration but I am new to this and I am not too sure how to approach this. By the way, I am using Kinetis Design Studio and KSDK. Any and all help is greatly appreciated.

ラベル(1)
55 返答(返信)

1,852件の閲覧回数
zoranmilosavlje
Contributor II

Alright. Thanks!

0 件の賞賛
返信

1,852件の閲覧回数
zoranmilosavlje
Contributor II

Hi dave408. So I have been looking at the reference manual for the MCU on this FRDM-K22F board (MK22FN512VLH12) and trying to evaluate the ADC/DAC converters. I am first trying to calculate on paper what the granularities/bit weights of these converters is. As you might now, bit weight is just the full-scale voltage range of the converter divided by 2^n, where n is the converters resolution or number of bits in the digital output. I know that the two A/D converters are 16-bit and the two D/A converters are 12 bit; but I am having trouble finding the full-scale voltage range of the converters in order to make my calculation. Do you know where I can find such information because I have not had any luck looking through the 1381 page reference manual on this MCU.

0 件の賞賛
返信

1,852件の閲覧回数
mjbcswitzerland
Specialist V

Zoran

pastedImage_0.png

In 16 bit mode the actual resolution depends on various setings and the effective maximum that can be obtained is "about" 14.5 bits. This means that any calculations with 16 bit are theoretical and not practical.

It makes sense to start a new thread with a new topic since this one already contains around 4 different subjects.

There is also no indication whether the other subjects are closed or not.

Regards

Mark

Kinetis: µTasker Kinetis support

K22: µTasker Kinetis FRDM-K22F support  / µTasker Kinetis TWR-K22F120M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

1,852件の閲覧回数
zoranmilosavlje
Contributor II

Hi Mark. I am trying to get an A/D converter working using the ADC component in Processor Expert but I am having some troubles. So what I am trying to set up on my FRDM-K22F board is use one of the ADC capable header pins as the analog input to which I will have a 3VDC source connected, and another pin on the header as the digital output from the ADC. I will hook up a logic analyzer to both of these pins and run some tests to make sure that the ADC is working properly.

So in order to actually output the digital signal from the ADC I decided to add a PWM component to my project as well which will create a PWM signal based on the output of the ADC:

pastedImage_2.png

I am having trouble how to set what pin I want to be the input to the ADC and what pin I want to be the output.

Here are my settings for PWM component:

pastedImage_4.png

Here are my settings for ADC component:

rtrtrtrtrtrtrtr.png

What do you think is the issue?

0 件の賞賛
返信

1,852件の閲覧回数
mjbcswitzerland
Specialist V

Hello Zoran

I don't use PE so can't help with this issue.

Regards

Mark

Kinetis: µTasker Kinetis support

K22: µTasker Kinetis FRDM-K22F support  / µTasker Kinetis TWR-K22F120M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 件の賞賛
返信

1,852件の閲覧回数
zoranmilosavlje
Contributor II

Hi Mark. A few weeks ago in one of your reply's above you mentioned that there are many ways to incorporate a timer:

1. Use the SysTick in the Cortex Core

2. In peripheral HW using PITs, FlexTimer, low power timer or (in some cases) RTC.

3. In HW using a serial peripheral such as SPI or UART (useful when no more HW timers are available)

4. In SW using a SW timer (which will ultimately be based on a HW tmer but shared for multiple SW usage)

So we know that one principal use of a timer is to pop an interrupt, but I don't care so much about the interrupt as I do about the register that does the actual counting. I want to be able to look at a hardware register at any time and save the 16-bit timer value at that moment. Whether it pops an interrupt is immaterial for these purposes what I want to do is use the hardware timer to measure time intervals. E.g. for timing a function, read the 16-bit timer when I enter it, and again when I leave it. So for these purposes I don't care about the interrupt. I am trying to look through the documentation to find the register that does the actual 'ticking'. Do you know how I could go about doing that?

0 件の賞賛
返信

1,852件の閲覧回数
dave408
Senior Contributor II

Look at page 833 of the K22 reference manual.  I've not used on one Kinetis before, but maybe a free running counter is what you want?

37.4.3.3 Free running counter

If (FTMEN = 0) and (MOD = 0x0000 or MOD = 0xFFFF), the FTM counter is a free

running counter. In this case, the FTM counter runs free from 0x0000 through 0xFFFF

and the TOF bit is set when the FTM counter changes from 0xFFFF to 0x0000. See the

following figure.

FTM counter 0x0003 0x0004 0xFFFE 0xFFFF 0x0000 0x0001 0x0002 0x0003 0x0004 0x0005 0x0006

TOF bit

... ... ...

FTMEN = 0

set TOF bit

MOD = 0x0000

Figure 37-172. Example when the FTM counter is free running

The FTM counter is also a free running counter when:

Chapter 37 FlexTimer Module (FTM)

K22F Sub-Family Reference Manual , Rev. 3, 7/2014

Freescale Semiconductor, Inc. 833

• FTMEN = 1

• QUADEN = 0

• CPWMS = 0

• CNTIN = 0x0000, and

• MOD = 0xFFFF

You can read FTMx_CNT to get the counter value.

0 件の賞賛
返信

1,852件の閲覧回数
zoranmilosavlje
Contributor II

Hi dave. Can you link me the reference manual you are looking at. It appears we are not looking at the same one.

0 件の賞賛
返信

1,852件の閲覧回数
dave408
Senior Contributor II
0 件の賞賛
返信

1,852件の閲覧回数
zoranmilosavlje
Contributor II

So we know that the FTM (FlexTimer Module) is a 16-bit free running counter. And we know that FTMx_CNT contains the FTM counter value. How could I incorporate a processor expert component to run a test to look at the FTMx_CNT when I pause the running program in Debug view to verify that FTM is counting?

In the Debug view there is a variables window:

pastedImage_1.png

So could I do something like this:

uint16_t myTime = 0;    // Declare a myTime variable to hold count value

while(1)

    {

        myTime = FTM_FTMx_CNT->TIMER

        status++;

    }

So if I run this would a variable name pop up into that variables window and the count would be shown in the value column?

0 件の賞賛
返信

1,852件の閲覧回数
zoranmilosavlje
Contributor II

Hi Mark. I am trying to build an example Kinetis project for my FRDM-K22F board but I am getting the following errors:

make: *** No rule to make target `C:/Freescale/KSDK_1.2.0/examples/frdmk22f/demo_apps/hwtimer_demo/kds/../../../../../lib/ksdk_platform_lib/kds/K22F51212/debug/libksdk_platform.a', needed by `hwtimer_demo_frdmk22f.elf'.    

make: Target `all' not remade because of errors.   

I have tried many things to solve this issue, but no success. Obviously if I can't build a project, I can't debug it, which is a huge issue. I need to get this solved quickly. What do you think I should try Mark?

Maybe my compiler path is not correct? How can I correct this?

0 件の賞賛
返信

1,852件の閲覧回数
dave408
Senior Contributor II

Zoran, if you get that error, you probably either haven't build libsdk yet, or your include path for the linker is wrong.  If you haven't build libsdk, you should do that first.  If you have, then one thing I do as a sanity check is to specify an absolute path in the linker settings so that you know it's pointing right at the .a.

0 件の賞賛
返信

1,852件の閲覧回数
zoranmilosavlje
Contributor II

EDIT:

I also just tried to set TMR_PERIOD to 1000000U which would give us a 1s timer and indeed it does as I verified with my logic analyzer. So it seems as if the timer is limited to only 2.023ms, what do you think about that?

0 件の賞賛
返信

1,852件の閲覧回数
zoranmilosavlje
Contributor II

The issue was that the library was not built. The program runs fine now. I have a question for you:

I have decided to try and find an example program which generates a timer to see how it is implemented and try to modify the code to generate a 1ms timer. So I have been looking at the hello_world_frdmk22f  sample program from Kinetis which flashes the green LED of the RGB package on the board. According to the FRDM-K22F schematics, this green LED is also connected to output port PTA2 which is a GPIO on one of the headers of the board. According to the define code in main.c of this program, the timer is set to 500000uS which is 500ms. To verify this timer visually I attach the logic probes onto the header pin to which the LED is hooked up to as you can see in this picture. And sure enough, the timer is ~ 500ms which you can see here.

But I am looking for a 1ms timer. So what I decided to simply do was change the TMR_PERIOD value to 1000U which = 1000us = 1ms. Then I go to measure this timer with my logic analyzer and I get 2.023ms which you can see here. Why do you think that is?

The code for reference (I bolded the timer period):

///////////////////////////////////////////////////////////////////////////////

//  Includes

///////////////////////////////////////////////////////////////////////////////

// SDK Included Files

#include "board.h"

#include "fsl_lptmr_driver.h"

#include "fsl_debug_console.h"

////////////////////////////////////////////////////////////////////////////////

// Definitions

////////////////////////////////////////////////////////////////////////////////

// Timer period: 500000uS

#define TMR_PERIOD         500000U

#if defined(TWR_KV46F150M)

#define LPTMR0_IDX LPTMR_IDX

#endif

////////////////////////////////////////////////////////////////////////////////

// Code

////////////////////////////////////////////////////////////////////////////////

/*!

* @brief LPTMR interrupt call back function.

* The function is used to toggle LED1.

*/

void lptmr_call_back(void)

{

    // Toggle LED1

    LED1_TOGGLE;

}

/*!

* @brief Main function

*/

int main (void)

{

    // RX buffers

    //! @param receiveBuff Buffer used to hold received data

    uint8_t receiveBuff;

    // LPTMR configurations

    lptmr_user_config_t lptmrConfig =

    {

        .timerMode = kLptmrTimerModeTimeCounter,

        .freeRunningEnable = false,

        .prescalerEnable = true,

        .prescalerClockSource = kClockLptmrSrcLpoClk,

        .prescalerValue = kLptmrPrescalerDivide2,

        .isInterruptEnabled = true,

    };

    // LPTMR driver state information

    lptmr_state_t lptmrState;

    // Initialize standard SDK demo application pins

    hardware_init();

    // Initialize LPTMR

    LPTMR_DRV_Init(LPTMR0_IDX, &lptmrState, &lptmrConfig);

    // Set timer period for TMR_PERIOD seconds

    LPTMR_DRV_SetTimerPeriodUs(LPTMR0_IDX, TMR_PERIOD);

    // Install interrupt call back function for LPTMR

    LPTMR_DRV_InstallCallback(LPTMR0_IDX, lptmr_call_back);

    // Start LPTMR

    LPTMR_DRV_Start(LPTMR0_IDX);

    // Initialize LED1

    LED1_EN;

    // Print the initial banner

    PRINTF("\r\nHello World!\n\n\r");

    while(1)

    {

        // Main routine that simply echoes received characters forever

        // First, get character

        receiveBuff = GETCHAR();

        // Now echo the received character

        PUTCHAR(receiveBuff);

    }

}

0 件の賞賛
返信