Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - enrico

Pages: [1] 2
1
Thank you, Mark! I really appreciate your help.

2
I think I might have found the reason why PWM is limited to 4MHz.

In kinetis.h
Code: [Select]
#if defined KINETIS_KL
    #if defined TPM_CLOCKED_FROM_OSCERCLK                                // {55}
        #define TIMER_CLOCK       (OSCERCLK)
    #elif defined TPM_CLOCKED_FROM_MCGIRCLK
        #define TIMER_CLOCK       (MCGIRCLK)
    #else
        #if defined FLL_FACTOR
            #define TIMER_CLOCK   (MCGFLLCLK)
        #else
            #define TIMER_CLOCK   (MCGPLLCLK/2)
        #endif
    #endif
    #define PWM_CLOCK             TIMER_CLOCK
#elif defined KINETIS_KE
    #define TIMER_CLOCK           (BUS_CLOCK)
    #define PWM_CLOCK             (BUS_CLOCK)
#else
    #define TIMER_CLOCK           (BUS_CLOCK)
    #define PWM_CLOCK             (SYSTEM_CLOCK/2)
#endif

and then in app_hw_kinetis.h:
Code: [Select]
    #define TPM_CLOCKED_FROM_MCGIRCLK                                    // TPM clock is connected to MCGIRCLK (either 32kHz or 4MHz)
    #define USE_FAST_INTERNAL_CLOCK

And finally in kinetis.h
Code: [Select]
#if defined USE_FAST_INTERNAL_CLOCK                                  // if not selected the slow internal clock is used (when needed)
        #define MCGIRCLK       FAST_ICR                                  // 4MHz, or 8MHz in mcg lite
    #else
        #define MCGIRCLK       SLOW_ICR

With the KL03 FAST_ICR should be 8MHz, thus the 4MHz limitation.


3
Hi Mark,

Thanks for your reply. I tried with the new macro, but still I can't get more than 4MHz. There is no output at all when
I'm running the MCU at 48MHz at the moment (from HIRC and clock divide=1), and using the version Kinetis_17-6-2015. Any idea? Should I try to update the kinetis_PWM to the latest version?

    #define RUN_FROM_HIRC                                                // clock from internal 48MHz RC clock
    #define SYSTEM_CLOCK_DIVIDE  1                                       // 1 to 16 - usually 1


4
NXPTM M522XX, KINETIS and i.MX RT / Generate output clock with KL03Z
« on: August 25, 2016, 10:04:52 PM »
Hi all,

I'd like to generate an internal clock from the KL03 and output the signal through a GPIO pin. Specifically I need a clock between 6 and 12MHz, which I'd like to use to drive an FPGA. I tried with the PWM modules, but it seems I can't go above 4MHz, and I'm not even sure this is the best approach. Is there a way to output directly to a pin one of the internal KL03 clocks?

Below is the code I'm currently using for the PWM approach that gives 4MHz output on PB11.

Code: [Select]

    PWM_INTERRUPT_SETUP pwm_setup;
    pwm_setup.int_type = PWM_INTERRUPT;
    pwm_setup.pwm_mode = (PWM_SYS_CLK | PWM_PRESCALER_1);             // clock PWM timer from the IRC48M clock with /1 pre-scaler
    pwm_setup.int_handler = 0;                                           // no user interrupt call-back or DMA on PWM cycle
    pwm_setup.pwm_frequency = PWM_TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(500000), 8);                   
    pwm_setup.pwm_value   = _PWM_PERCENT(50, pwm_setup.pwm_frequency);   // 50% PWM (high/low)
    pwm_setup.pwm_reference = (_TIMER_0 | 0);                            // timer module 0, channel 0
    fnConfigureInterrupt((void *)&pwm_setup);                            // enter configuration


Thank you,
Enrico

5
NXPTM M522XX, KINETIS and i.MX RT / Re: KL03Z and low power modes
« on: November 12, 2015, 05:30:41 AM »
Hi Mark,

Thanks for your analysis, that really helps!

I've done my homework too, and here are my measurements:
RUN 5.8mA
WAIT 2.3mA
STOP 160uA
VLSP 5uA
VLL0 2.5uA

Except for VLL0 (which should be much lower), my measurements are fairly close to the ones here (from pg 11)
http://cache.freescale.com/files/32bit/doc/data_sheet/KL03P24M48SF0.pdf

Your STOP measurement seems very low instead. Do you have any idea why is that?

I've also reduced the clock to 3MHz and I get RUN around 1.8mA and WAIT around 1.2mA.


I have also some observations about the freezing problem with lower clock. I have the FPGA  board connected to the MCU via SPI. The FPGA is just waiting for the SPI clock from the MCU.
- With low clock frequency, if I power the FPGA before the MCU, the latter freeze in the initialization. After the MCU is initialized (the LED blinks), I can power the FPGA with no problem.
- This initialization time increases substantially when I lower the clock of the MCU.
- The freezing occurs when the MCU clock becomes lower or equal than the FPGA board clock (12MHz)

From these observations, it seems like some of the SPI pins get during initialization some signal from the FPGA board that cause interrupts/resets? Does this make any sense to you?

Thanks,
Enrico


6
NXPTM M522XX, KINETIS and i.MX RT / Re: KL03Z and low power modes
« on: November 11, 2015, 07:51:21 PM »
Thanks for the useful information. I will start by reproducing your results. For the RUN and WAIT mode they are not too far from what I've measured.

Few clarifications:
- Are you measuring the MCU energy only through J10?
- When you say RUN_FROM_HIRC (48Mhz core) with 32kHz RTC oscillator, what do you exactly mean?
- How do you go from STOP and VLPS to RUN? Since tick is not operating I guess you are using LLWU, right?

Thanks
Enrico

7
NXPTM M522XX, KINETIS and i.MX RT / Re: KL03Z and low power modes
« on: November 11, 2015, 05:35:11 AM »
Thanks, I will start from that for the LP modes.


In the meanwhile, I tried to lower the clock speed of the MCU while in run or wait mode. I don't need the 48MHz, I would like to go down to 1MHz.

As a first step, I am trying to go down to 8MHz.

In app_hw_kinetis.h I have
 //  #define RUN_FROM_HIRC                                                // clock from internal 48MHz RC clock
  #define RUN_FROM_LIRC                                                // clock from internal 8MHz RC clock

and
  // #define LPUART_IRC48M                                            // if the 48MHz clock is available clock the LPUART from it
      //#define LPUART_OSCERCLK                                          // clock the LPUART from the external clock
         #define LPUART_MCGIRCLK                                          // clock the LPUART from MCGIRCLK (IRC8M/FCRDIV/LIRC_DIV2)

However, when I power the MCU it kind of freeze and I can see the green light getting stuck. I did some debug and it looks like the board is resetting (fnInitHw is called repeatedly). I see some similarity to what you have experienced here https://community.freescale.com/thread/335304

Any idea of what am I doing wrong?


Another interesting aspect is that, If i connect the SPI clk pin of the MCU (master) to ground, than the core start running and the LED blinking (and lower energy consumption because of the reduced clock). If I deactivate the SPI module, then connecting to ground the clk pin does not have any effect.

Thanks,
Enrico

8
NXPTM M522XX, KINETIS and i.MX RT / Re: KL03Z and low power modes
« on: November 10, 2015, 05:19:24 AM »
Thanks for the advice, Mark.

Do you have any reference from where I could start with the lower power modes?

I have started with stop mode, and a simple interrupt doesn't wake up the MCU. I will try with the lptmr module as suggested in
http://www.utasker.com/kinetis/LLWU.html
Is there any example that use this wake up method?

Also, I've enabled #define SUPPORT_LPTMR in app_hw_kinetis, whichs also enabled  #define TICK_USES_LPTMR. By doing this it seems that a simple interrupt works fine to awake the MCU from stop mode. Is there any documentation about this? What is the advantage of using LPTMR as tick?

Thanks!

9
NXPTM M522XX, KINETIS and i.MX RT / Re: KL03Z and low power modes
« on: November 09, 2015, 08:36:47 PM »
Apparently I had a few problems with my previous setup.

1) I was measuring the power consumption of the board by powering the 3.3V pin in J3-4 . However, I was measuring about 30/40mA, which was suspiciously too high.

Turns out that there was some loop between the KL03 board and the FPGA board that I have connected to it. Specifically, the interrupt wire that is going from the FPGA to PTB3 of the kl03 board (as default in nRF24201.c that I used as SPI reference) was actually powering the kl03 board (!?). Now I've changed PTB3 to PTB7, and the problem is gone. Is this a problem with my board?

With this configuration the board gets about 10mA in wait mode.

2) I was measuring the power consumption of the board, not the power consumption of the MCU. Now I am using the J10 jumper, after removing R27 and R32 from the board as in pg 5
http://cache.freescale.com/files/microcontrollers/doc/user_guide/FRDMKL03ZUG.pdf
or in
http://mcuoneclipse.com/2013/10/20/tutorial-using-the-frdm-kl25z-as-low-power-board/

The Freescale guide says R27 is enough. In other Freescale board guides they mention to remove the 0-R if you use a voltmeter or both if you use an ammeter.

Now, I am powering the board via USB or J2-4, and the MCU through J10-2. The measuring device is providing 3V to J10-2 and measuring the current drawn.
Using this setup I get 2.3mA in wait mode and 5.8 in run mode, not too far from this (pg 11)
http://cache.freescale.com/files/32bit/doc/data_sheet/KL03P24M48SF0.pdf?pspll=1

Does this setup sound reasonable to you?

Thanks,
Enrico

PS. FYI, when I comment #define SERIAL_INTERFACE  in config.h, I get a build error in kinetis.c in
Code: [Select]
#if defined KINETIS_KL03
    _LPSCI0_Interrupt,
    #else

10
NXPTM M522XX, KINETIS and i.MX RT / Re: KL03Z and low power modes
« on: November 09, 2015, 04:32:39 PM »
Thank you, Mark.

The measuring system can support up to 28mA, and apparently the board is taking up much more that that (between 30 and 40mA). I guess the intermitting behavior is due to exceeding the maximum current. This might be useful to reduce the board power consumption:
http://mcuoneclipse.com/2013/10/20/tutorial-using-the-frdm-kl25z-as-low-power-board/

I will try that and then go back and try different low power modes.

Thanks for your help.

Enrico

11
NXPTM M522XX, KINETIS and i.MX RT / KL03Z and low power modes
« on: November 06, 2015, 10:43:56 PM »
Hello,

I am studying how uTasker manages low power modes for the KL03Z MCU. My final objective is to bring the MCU to a very low energy state (ideally very low leakage state) and use a low power timer to awake it every once in a while. Does this sound reasonable and feasible with the KL03Z?

Starting from this interesting wiki
http://www.utasker.com/kinetis/LLWU.html
I've learned that uTasker is already switching from WAIT to RUN when there are operations to perform and to STOP when there are no tasks to perform. Is this correct? Does this apply for the KL03 as well or it uses very low power states?


By analyzing the MCU energy consumption, I get an intermitting behavior that confirms what said above. The screenshot below shows the energy and the accumulated energy in time (uJ and s units).
https://www.dropbox.com/s/bmxfjf8nhjm35a3/Screenshot%202015-11-06%2016.23.27.png?dl=0

However, the off times give very low energy consumption (I get zero, which means current is lower than 500nA that is the measuring sensitivity), that does not match the energy consumption of the STOP mode provided in the data sheet. Is it really going to STOP mode? I guess this is performed into fnDoLowPower function, but I can't understand to what state this is going.

Also, the off times are about 0.2s while the on times are about 0.4s. Is this because of the watchdog? I currently have only an SPI transmission task every 4 seconds.

Looking forward to hearing from you.

Best,
Enrico


12
NXPTM M522XX, KINETIS and i.MX RT / Re: FRDM-KL03Z debug, LED and SPI
« on: October 17, 2015, 12:30:34 AM »
Hi Mark,

By default I am using PTB3. The problem is happening independently from the point where I configure the interrupt.

I did some debug and the code is getting stuck here
Code: [Select]
#if defined USE_MAINTENANCE && (!(defined KWIKSTIK && defined SUPPORT_SLCD))
        fnInitialisePorts();                                             // set up ports as required by the user
#endif

I commented #define USE_MAINTENANCE in config.h and now it works. I am pretty sure it was running out of memory.

Thank you,
Enrico

13
NXPTM M522XX, KINETIS and i.MX RT / Re: FRDM-KL03Z debug, LED and SPI
« on: October 16, 2015, 03:12:15 AM »
Thanks Mark! Now it works with IRC48. I am pretty sure I didn't change that setting. For my understanding, what is the purpose of this setting?


Moving forward with my implementation, I am able to send and receive data to and from an FPGA through SPI. As a next step, I want to set an port type interrupt coming from the FPGA. I've started from the nRF24201.c code for the SPI setting and transmission. Now I am trying to reuse that code for setting the interrupt as well. However, as soon as I configure the interrupt, the system just doesn't work. No blinking led, no UART, no SPI. I guess it get stuck somewhere in the port initialization (a memory issue?).

As a note. I've observed this behavior with the original code as well (before I started implementing my changes). To make it works, I always had to comment the interrupt configuration.

Any idea on that?

This is my initialization code (exactly as in RF24201.c):
Code: [Select]
INTERRUPT_SETUP interrupt_setup;                                     // interrupt configuration parameters
    interrupt_setup.int_type       = PORT_INTERRUPT;                     // identifier to configure port interrupt
    interrupt_setup.int_handler    = fn_nRF24L01_interrupt;              // handling function
    interrupt_setup.int_priority   = nRF24L01P_IRQ_PRIORITY;             // interrupt priority level
    interrupt_setup.int_port       = nRF24L01P_IRQ_PORT;                 // the port that the interrupt input is on
    interrupt_setup.int_port_bits  = nRF24L01P_IRQ;                      // the IRQ input connected
    interrupt_setup.int_port_sense = (IRQ_FALLING_EDGE | PULLUP_ON);     // interrupt is to be falling edge sensitive
    fnConfigureInterrupt((void *)&interrupt_setup);                      // configure interrupt

Thank you,
Enrico

14
NXPTM M522XX, KINETIS and i.MX RT / Re: FRDM-KL03Z debug, LED and SPI
« on: October 14, 2015, 01:15:49 AM »
Thank you, Mark.

I am attaching two zip files with bin and map files for the two different LPUART clocks.

Enrico


15
NXPTM M522XX, KINETIS and i.MX RT / Re: FRDM-KL03Z debug, LED and SPI
« on: October 13, 2015, 05:11:27 PM »
Mark,

I had a chance to test the code.

About (3), now MCGIRCLK is working correctly at 19200. Just three questions to make sure I'm doing it right:
- KINETIS_WITH_MCG_LITE  was not defined anywhere, right? I defined it into config.h under the kl03 define.
- You wrote  "#define SLOW_ICR       32768", while the code was originally  "#define SLOW_ICR       32000". Would this create a problem?
- In kinetic.UART.h, I've adjusted the divider for SPECIAL_UART_CLOCK. Should I do the same in BUS_CLOCK and SPECIAL_LPUART_CLOCK?


About (2), I have #define RUN_FROM_HIRC. But still I can get any output out of the UART when i select IRC48. Really strange. I think I haven't changed any clock setting.

Thank you!

Pages: [1] 2