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 - Raffaele

Pages: [1] 2 3 ... 5
1
utFAT / Re: Reading UART messages of different lengths
« on: May 05, 2021, 10:44:49 PM »
Thanks Mark, you confirmed what I had assumed. Unfortunately I don't use a protocol that tells the size of the messages and using fnMsgs() would give me the same behavior, nor I have  a specific termination character. I think I can make the delay work then.

Thank you

2
utFAT / Reading UART messages of different lengths
« on: May 05, 2021, 06:08:15 PM »
Hi,
I'm trying to read UART messages of any length on a KL03 (does not support DMA).
I use fnRead in my task, and every time a new character is received the task is triggered.
My code is very simple

Code: [Select]
QUEUE_TRANSFER length;
while (   (length = fnRead(SerialPortID, uartMessage, MEDIUM_MESSAGE)) != 0 ){
counter++;
//fnDelayLoop(600);
}

Now, here is the problem, if I do not use that fnDelayLoop, the while is entered for each character, one at a time. So, for a message of n chars, there will be n interrupts to my task and n while loops. If, instead, I use the fnDelayLoop, the while is executed only one time for the whole message (which I prefer). My understanding is that without the delay, the while terminates because the characters are too slow with respect the the execution of the while loop and the uart rx buffer is empty, so the delay allows waiting for the whole message to arrive while still in the loop.

But in this way the delay to to be used depends on the length of the message that I don't know beforehand and it is not constant. And if the delay is not enough for a long messages, then its last part will come with the initial part of the next message.
Is there a better way to do this?

3
µTasker general / Re: Device doesn't retain low power configs
« on: March 02, 2021, 08:20:08 PM »
No worries about late reply Mark, thank you I appreciate your help.

Apparently there were three causes of error in my set-up: 1) as you pointed out, I needed to power cycle the board between programming it, 2) I had a signal analyzer connected to the board that was changing the absorbed current and gave inconsistent results, 3) I was trying to read an interrupt that was too short for the low power clock and the microcontroller wasn't able to catch it and it seemed like something stopped working.

Thanks

4
µTasker general / Re: Device doesn't retain low power configs
« on: February 26, 2021, 05:31:47 PM »
any help on what could cause the issue? Is it probably the fnLowPower task , but why would it work in one case (i.e., program device - turn off - turn on - reprogram) and not in the other (program - turn off - turn on)?


EDIT Update: I'm using some interrupt signals and it looks like my code gets stack when I inform that I want to enter VLPS (fnSetLowPowerMode(VLPS_MODE)). At that point, the task doesn't get activated any more when I use uTaskerMonoTimer('j', (DELAY_LIMIT) (5 * SEC), UTASKER_ACTIVATE);

5
µTasker general / Device doesn't retain low power configs
« on: February 23, 2021, 08:56:50 PM »
Hi,

sorry if the title is misleading.
I'm having issues with programming a KL03. The code that I program the device with has a low power task that periodically moves from VLPW to VLPS, and vice versa.
If I:
Program the device -> Power it off -> Power it on again
Or
Power it on -> Program with recompiled code (even the same exact code, just freshly recompiled)
 it stalls at the beginning (but I think neither in VLPW nor in VLPS, because the power consumption is larger than VLPW and lower than VLPS. I measured  the powers for each state).
Instead, if I:
Program the device -> Power it off -> Power it on -> RE-PROGRAM with the same code (not recompiled), then it works properly, and alternates between VLPW and VLPS.

What could it be?
My intuition is that during reprogramming something gets pulled high/low, probably for a certain amount of time necessary for my device to work properly.  And since this doesn't happen with a simple restart, the device/code gets stuck somewhere


6
µTasker general / Re: MCG_Lite Clock mode switching
« on: February 18, 2021, 04:33:14 AM »
Great, it all makes sense. It's working

Thank you

7
µTasker general / Re: MCG_Lite Clock mode switching
« on: February 15, 2021, 08:46:37 PM »
Hi Mark,


yes my basic mode of operation is from the IRC48M. However, the only reason I start from IRC48M is because, as it appears from the MCG_Lite mode state diagram (see attached illustration) I can't go directly from LIRC8M to LIRC2M and viceversa, but I need to go to IRC48M first.
But from your answer 4 it looks like I'm wrong and I could go directly from  LIRC8M to LIRC2M (?)

1. If I understood correctly, the FCRDIV is set with the SLOW_CLOCK_DIVIDE as I can also see from this snippet of kinetis.h

Code: [Select]
      #elif defined RUN_FROM_LIRC
            #if defined RUN_FROM_LIRC_2M
                #define IRC_CLOCK      2000000
            #else
                #define IRC_CLOCK      8000000
            #endif
            #if defined SLOW_CLOCK_DIVIDE
                #if (SLOW_CLOCK_DIVIDE == 1)
                    #define SLOW_CLOCK_DIVIDE_VALUE  (MCG_SC_FCRDIV_1)
                #elif SLOW_CLOCK_DIVIDE == 2
                    #define SLOW_CLOCK_DIVIDE_VALUE  (MCG_SC_FCRDIV_2)
                #elif SLOW_CLOCK_DIVIDE == 4
                    #define SLOW_CLOCK_DIVIDE_VALUE  (MCG_SC_FCRDIV_4)
                    ...
                    ...


 2. No, I don't plan to use peripherals, like UART, so I don't need LIRC_DIV2. But I'm using SPI, so I need BUS_CLOCK_DIVIDE.

So here are a couple of questions on the logic of OUTDIV1, OUTDIV4 and BUS_CLOCK_DIVIDE.
a) Do I just need to set a value for the main clock and BUS_CLOCK_DIVIDE and uTasker will automatically define the values for OUTDIV1 and OPUTDIV4?
b) If I switch from LIRC8M to LIRC2M, can I  (and if so, how?), change the values for  SLOW_CLOCK_DIVIDE, or BUS_CLOCK_DIVIDE? Since the clock is slower now, I might need to update them.

3. How can I disable IRC48M when I don't need it any more?


Yes I remember the issue with UART with slower clocks and you already helped me fix it  8)

Thanks,
Raff

8
µTasker general / MCG_Lite Clock mode switching
« on: February 12, 2021, 09:28:23 PM »
Hi,

I'm trying to switch clock mode on the KL03 from within my own task.
The "KL03 Sub-Family Reference Manual" https://www.nxp.com/docs/en/reference-manual/KL03P24M48SF0RM.pdf
on pg. 321 reports how to switch between clk modes.


I took a look at the file kinetis.c and I saw that the following instructions (not in this order) are used:

Code: [Select]
MCG_C2 |= MCG_C2_IRCS;                                               // select fast internal reference clock
MCG_C1 = MCG_C1_CLKS_HIRC;                                           // select HIRC clock source
MCG_C2 &= ~MCG_C2_IRCS;                                              // select slow internal reference clock
MCG_C2 = 1;
MCG_C2 = 0;

I have 2 questions:

1]
If I want to enter LIRC8 and move to LIRC2, passing by HIRC, I just use this set of instructions in this order in my task. Is this correct and enough?

Code: [Select]
//Enter LIRC8
MCG_C2 &= ~MCG_C2_IRCS;                                              // select slow internal reference clock
MCG_C2 = 1;

//Enter HIRC
MCG_C2 |= MCG_C2_IRCS;                                               // select fast internal reference clock
MCG_C1 = MCG_C1_CLKS_HIRC;                                           // select HIRC clock source

//Enter LIRC2
MCG_C2 &= ~MCG_C2_IRCS;                                              // select slow internal reference clock
MCG_C2 = 8;


2] What do I do with the macros in the file app_hw_kinetis.h since I would need both RUN_FROM_HIRC and RUN_FROM_LIRC? I mean, do I need to uncomment both?

Code: [Select]
#define RUN_FROM_HIRC                                                // clock from internal 48MHz RC clock
#define RUN_FROM_LIRC                                                // clock from internal 8MHz/2MHz RC clock
    #if defined RUN_FROM_HIRC
        #define SYSTEM_CLOCK_DIVIDE  2                                   // 1..16
        #define BUS_CLOCK_DIVIDE     2                                   // 1..8 (valid for bus/flash and divisor is after the system clock divider)
    #elif defined RUN_FROM_LIRC
        #define RUN_FROM_LIRC_2M                                         // select 2MHz rather than 8MHz
        #define SLOW_CLOCK_DIVIDE    2                                   // optionally divide the slow clock output (1, 2, 4, 8, 16, 32, 64 or 128)
        #define SYSTEM_CLOCK_DIVIDE  1                                   // 1..16
        #define BUS_CLOCK_DIVIDE     1                                   // 1..8 (valid for bus/flash and divisor is after the system clock divider)

Thank you

9
µTasker general / conditionally execute interrupt handler function
« on: January 16, 2021, 06:33:25 AM »
Hi,

I'm using the KL03. I have two independent parallel tasks.
One task changes from one state to another periodically. This is the simplified code:

Code: [Select]
case 1:
nState  = 2;
uTaskerMonoTimer('B', (DELAY_LIMIT) (2 * SEC), UTASKER_ACTIVATE);
break;

case 2:
nState = 1;
uTaskerMonoTimer('B', (DELAY_LIMIT) (3 * SEC), UTASKER_ACTIVATE);
break;


The other task configures a port interrupt (on a GPIO pin) and its handling function fn_rx_interrupt_handler is called whenever the interrupt is triggered externally on that pin.

Code: [Select]
static void fn_rx_interrupt_handler(void) {
fn_b();
}

All this works.

Now, I want that fn_b() is executed ONLY if nSTate==1, so I simply do:

Code: [Select]
static void fn_rx_interrupt_handler(void) {
if (nState == 1) {
fn_b();
}
}
But this doesn't work. The task ignores the interrupt. Even if I try to put the control of nState in fn_b, it still doesn't work. It is as if that if statement in the interrupt disables it

Any idea why and what I can do?

10
µTasker general / UART Tx stalls and incomplete messages
« on: December 23, 2020, 07:02:58 PM »
Hi,

I'm working with a KL_03 using the UART to transmit (no DMA, just base mode) and I am having issues. Is there anything I need to pay attention to in terms of UART Tx buffer size, baud rate, and transmission duration? Is there a correlation between them, such as a certain buffer size only works with some specific baud rates?

I have a task that runs periodically every few seconds, at each run I print UART messages of different lengths using fnDebugMsg():
1) some messages are cut or not printed completely
2) after some printouts the code stalls (I'm debugging it to understand if the problem is somewhere else or related to UART)
3) I use fnDelayLoop(x) after UART messages, but it looks like that it sometimes helps write more complete messages, other times it doesn't. I don't know how to choose the value for x



Thank you

11
µTasker general / Change Timer/Channel associated pin for PWM
« on: November 11, 2020, 11:11:53 PM »
Hi,

I'm trying to generate two different PWMs on a KL03. One uses pwm_reference = (_TIMER_1 | 0); and the associated pin is PTA0. This works.
For the other one I want to use PTA12. However, the KL family manual reports  TPM1_CH0 for both PTA0 and PTA12.

To change this, in the file kinetis_PWM.h I changed _CONFIG_PERIPHERAL(B, 11,(PORT_MUX_ALT2 | PORT_SRE_FAST | PORT_DSE_HIGH)); to _CONFIG_PERIPHERAL(A, 12,(PORT_MUX_ALT2 | PORT_SRE_FAST | PORT_DSE_HIGH));
so that the pwm_reference for PTA12  is now  TPM0_CH0 instead of  TPM1_CH0.

I set up 2 different PWMs on PTA0 and PTA12, but both pins generate the same PWM of  TPM1_CH0 A0. In other words, I am not able to modify the PWM on PTA12. Is there anything else I need to change in the code?

12
µTasker general / Re: UART, SPI and PWM in low power modes
« on: October 20, 2020, 02:59:18 AM »
I'm getting there. My current consumption is high probably due to how the KL03 is connected to other stuff. From VLPS down to VLLSx's I always have the same current (0.66uA). I'll try with a fresh board and see if I can get the same current values discussed in this thread: https://www.utasker.com/forum/index.php?topic=1908.0

Meanwhile I have a couple of questions.

Q1)
In STOP/VLPS modes the MCG-Lite is static and the LIRC can be optionally enabled. In fact, I see that in STOP/VLPS, the PWM doesn't work (while it works in VLPW, VLPR etc). The KL03 manual says: "To enable LIRC in Stop mode, write 1b to MCG_C1[IREFSTEN] and MCG_C1[IRCLKEN] before entering Stop mode". How can I enable this behavior in uTasker? Is it implemented or do I have to write in those registers every time before entering VLPS?

Q2)
Since I'm trying to save power, I was wondering what are the other possibilities to generate the PWM and if the LPTMR might be useful in my scenario.
My scenario is this: I want to generate a sequence of pulses that is on all the time, and asynchronous UART or SPI from time to time (slow data rates in the order of kHz are acceptable). Furthermore, my PWM has a relatively low frequency and very low duty cycle. It is a 130Hz signal with about 30us pulses (so the highest source frequency needed for the pulses is 30-34kHz). If there is a solution to Q1 I can do this with LIRC in VLPS.
Alternatively, another strategy could be, keeping LIRC static and generating the pulses differently. Something like a periodic "wakeup" that about every 130ms generates a 30us pulse which might also save more power since the duty cycle is low? Or maybe there is another clock that I can use in VLLSx modes, in which case I could generate an LLWU interrupt and restart when I need to use SPI (https://www.utasker.com/kinetis/LLWU.html)

13
µTasker general / Re: UART, SPI and PWM in low power modes
« on: October 17, 2020, 04:53:25 PM »
Thank you so much Mark,
I'm going through your answer and testing.
As for the UART I was trying to send instead of receiving, that's probably why I couldn't make it work? I will try to rx and see what happens.

Besides all the functionalities (UART, SPI etc), at the moment I'm having trouble to actually enter a low power stop or low leakage state as my current consumption is always around 0.9mA or higher. It's like I'm always in WAIT mode.
I tried to run from HIRC or from LIRC with these configs

Code: [Select]
//#define RUN_FROM_HIRC                                                // clock from internal 48MHz RC clock
  #define RUN_FROM_LIRC                                                // clock from internal 8MHz/2MHz RC clock
    #if defined RUN_FROM_HIRC
        #define SYSTEM_CLOCK_DIVIDE  16                                   // 1..16
        #define BUS_CLOCK_DIVIDE     4                                   // 1..8 (valid for bus/flash and divisor is after the system clock divider)
    #elif defined RUN_FROM_LIRC
        #define RUN_FROM_LIRC_2M                                         // selet 2MHz rather than 8MHz
        #define SLOW_CLOCK_DIVIDE    2                                   // optionally divide the slow clock output (1, 2, 4, 8, 16, 32, 64 or 128)
        #define SYSTEM_CLOCK_DIVIDE  8                                   // 1..16
        #define BUS_CLOCK_DIVIDE     2                                   // 1..8 (valid for bus/flash and divisor is after the system clock divider)

Plus, I have
#define SUPPORT_LOW_POWER
#define SUPPORT_PORT_INTERRUPTS
(I will need it for LLWU)

{"lowPower",  fnLowPower,   NO_QUEUE,  0, 0, UTASKER_GO} is activated in taskConfig.c

As soon as I enter my TASK I run fnSetLowPowerMode(RUN_MODE) or WAIT_MODE, or VLPR_MODE (and it works), but after that all other modes like VLPS_MODE, VLLS0_MODE, I think are entered because I see the current decreasing, but it's no lower than 0.9mA.

Is there any other settings/define or wrong clock I am missing?


14
µTasker general / UART, SPI and PWM in low power modes
« on: October 15, 2020, 09:31:12 PM »
Hi,
I'm writing a task for the KL03 that generates a PWM and sometimes uses SPI master and UART. I need it to be as low power as possible.

1)
According to the KL manual* (page 84) in VLPS, UART and TPM can work as far as their clock sources are enabled (table pg 81). How do I enable them in utasker?

2) I want to use the function fnSetLowPowerMode but for it to be functional, the task    {"lowPower",  fnLowPower,   NO_QUEUE,  0, 0, UTASKER_GO} in taskConfig.c has to be enabled. Does it make sense?

3)
I'm using the function fnSetLowPowerMode(VLPS_MODE); to enter VLPS mode, but when I do it UART stops working, probably because of question (1). SPI also stops working but that's expected because SPI master works up to VLPW at 500kbps (table pg 84) correct?

4)
Is it possible to switch from VLPS_MODE to VLPW_MODE, for example, when I need to use the spi, and then back to VLPS?


* https://www.nxp.com/docs/en/reference-manual/KL03P24M48SF0RM.pdf

15
µTasker general / Re: SPI configs increases current absorption of 70mA
« on: October 01, 2020, 11:39:21 PM »
Related to this topic, so I don't open a new one. After configuring an SPI interface, by calling INITIALISE_SPI_SD_INTERFACE() as defined below, is it possible to disable/undefine it?



 
This is my config, just regular SPI:

Code: [Select]
#define INITIALISE_SPI_SD_INTERFACE()  POWER_UP(4, SIM_SCGC4_SPI0); \
                        _CONFIG_PERIPHERAL(B, 0, PB_0_SPI0_SCK); \
_CONFIG_PERIPHERAL(A, 7, (PA_7_SPI0_MOSI | PORT_SRE_FAST | PORT_DSE_HIGH)); \
_CONFIG_PERIPHERAL(A, 6, (PA_6_SPI0_MISO | PORT_PS_UP_ENABLE)); \
_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, SPI_CS1, SPI_CS1, (PORT_SRE_FAST | PORT_DSE_HIGH));\
_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, SPI_CS2, SPI_CS2, (PORT_SRE_FAST | PORT_DSE_HIGH));\
SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE); \
SPI0_BR = (SPI_BR_SPPR_PRE_4 | SPI_BR_SPR_DIV_2); \
(void)SPI0_S; (void)SPI0_D;


Pages: [1] 2 3 ... 5