Recent Posts

Pages: [1] 2 3 ... 10
1
µTasker general / Re: Sleep-receive state machine with timeouts
« Last post by mark on September 13, 2020, 11:46:20 PM »
Hi

I would use states and events to better control a state machine.

Could you try something like this?

Code: [Select]
// States
#define START_DELAY 1
#define SLEEP       1
#define RX          2

// Events
#define GO_TO_SLEEP 1
#define GO_TO_RX    2

#define MY_TASK     'C'

extern void stateMachineTask(TTASKTABLE *ptrTaskTable) {
    static int iState = 0;
    QUEUE_HANDLE        PortIDInternal = ptrTaskTable->TaskID;           // queue ID for task input
    unsigned char       ucInputMessage[HEADER_LENGTH];                   // reserve space for receiving messages
    int iEvent = 0;

    if (fnRead(PortIDInternal, ucInputMessage, HEADER_LENGTH) == 0) { // check task input queue
        iEvent = ucInputMessage[MSG_TIMER_EVENT];
    }

    switch (iState) {
    case 0:
        uTaskerMonoTimer(MY_TASK, (DELAY_LIMIT)(0.5 * SEC), GO_TO_RX);
        iState = START_DELAY;
        break;

    case START_DELAY:
        steupIinterruptHandler();
        // Fall-though intentionally
        //
    case SLEEP:
        if (iEvent == GO_TO_RX) {
            activate_data_processing();
            iState = RX;
            uTaskerMonoTimer(MY_TASK, (DELAY_LIMIT)(T2 * SEC), GO_TO_SLEEP);
            uTaskerStateChange(MY_TASK, UTASKER_ACTIVATE);
            break;
        }
        // do sleep operations here
        break;

    case RX:
        if (iEvent == GO_TO_SLEEP) {
            deactivate_data_processing();
            iState = SLEEP;
            uTaskerMonoTimer(MY_TASK, (DELAY_LIMIT)(T1 * SEC), GO_TO_RX);
            uTaskerStateChange(MY_TASK, UTASKER_ACTIVATE);
            break;
        }
        // if received interrupt, process data
        break;
    }
}

Regards

Mark
2
µTasker general / Sleep-receive state machine with timeouts
« Last post by Raffaele on September 13, 2020, 05:53:13 PM »
Hi,
I'm trying to implement a state machine but I am having issues with the task.
I simply have two states: SLEEP and RX and I want to do

1) stay in SLEEP for T1 sec
2) after T1 sec go to RX
3) stay in RX for T2 sec (if something is received, aka interrupt on a pin, process data)

All these things work independently in my code. But I don't know how to properly activate the task


Code: [Select]
int const SLEEP = 1;
int const RX = 2;

extern void stateMachineTask(TTASKTABLE *ptrTaskTable){
switch (iState) {

case 0 :
steupIinterruptHandler();

iState = 1;
uTaskerMonoTimer('C', (DELAY_LIMIT) (0.5 * SEC), UTASKER_ACTIVATE);
break;

case SLEEP :

deactivate_data_processing();

// do sleep operations here

iState = RX;
uTaskerMonoTimer('C', (DELAY_LIMIT) (T1 * SEC), UTASKER_ACTIVATE);
break;

case RX :
activate_data_processing();

//if received interrupt, process data

iState = SLEEP;
uTaskerMonoTimer('C', (DELAY_LIMIT) (T2 * SEC), UTASKER_ACTIVATE);
break;
}
}

My major problem is that the interrupt is not triggered (it normally works). If I can suspend/resume the whole task that's fine too, but I don't know how to do it
3
NXPTM M522XX, KINETIS and i.MX RT / i.MX RT XBAR + AOI modules introduced
« Last post by mark on September 03, 2020, 03:42:08 AM »
Hi All

New video showing XBAR and AOI in operation:
https://youtu.be/zNWIG-O7ZW0

Regards

Mark
4
µTasker general / Re: SPI configs increases current absorption of 70mA
« Last post by mark on August 27, 2020, 12:33:47 PM »
Hi

The alternative settings are correct as you have defined them - it is also not possible to use a normal GPIO for clocking if the SPI is used (any GPIO be used by bit-banging, but all signals would need to be bit banged and thus the SPI would not be used at all).

Here are the complete KL03 SPI0 MUX settings:

    #define PA_5_SPI0_SS_b               PORT_MUX_ALT3
    #define PB_10_SPI0_SS_b              PORT_MUX_ALT3
    #define PB_0_SPI0_SCK                PORT_MUX_ALT3
    #define PA_9_SPI0_SCK                PORT_MUX_ALT3
    #define PA_7_SPI0_MOSI               PORT_MUX_ALT3
    #define PA_8_SPI0_MOSI               PORT_MUX_ALT3
    #define PA_7_SPI0_MISO               PORT_MUX_ALT2
    #define PA_6_SPI0_MISO               PORT_MUX_ALT3
    #define PB_11_SPI0_MISO              PORT_MUX_ALT3


Regards

Mark

5
µTasker general / Re: SPI configs increases current absorption of 70mA
« Last post by Raffaele on August 25, 2020, 05:32:30 PM »
A slightly unrelated question.

_CONFIG_PERIPHERAL(B, 0, PB_0_SPI0_SCK) defines the CLK pin. For the KL03, the family manual says that PB_0, PA_9 or PB_11 can be used as clock lines (depending on the chip).

I am assuming that if I want the clock on PA_9, then I need to do:
_CONFIG_PERIPHERAL(A, 9, PA_9_SPI0_SCK);

and add:

#define PA_09_SPI0_SCK PORT_MUX_ALT3, as PA_09_SPI0_SCK is not defined in the code.

Does it sound correct?

But, I can't use a generic GPIO pin for the CLK, like PA_8, can I?
6
µTasker general / Re: SPI configs increases current absorption of 70mA
« Last post by Raffaele on August 21, 2020, 04:38:47 PM »
Fantastic, Mark!

I tried the lines 1 by 1 and I found out that the issue was the clock. It interfered with the clock of the device it is connected to, as the other device can be master or slave but I hadn't configured it as slave.

Great,
thanks
7
µTasker general / Re: SPI configs increases current absorption of 70mA
« Last post by mark on August 20, 2020, 02:39:36 AM »
Hi

I would still try disabling the pins since when the SPI is enabled it will start driving outputs.
Also - is the additional current consumption maybe due to the SPI slaves rather than the KL03? The SPI slaves may consume current when selected by their CS lines).
Are the SPI slaves connected correctly (eg. is it possible that their SOUT lines are connected to the KL03's SOT line rather than SIN?)

Regards

Mark
8
µTasker general / Re: SPI configs increases current absorption of 70mA
« Last post by Raffaele on August 19, 2020, 12:05:36 AM »
Thanks  Mark,

so the problem seems to be caused by SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE); if I remove this line the current consumption stays at 3mA.
Now you see I have two chip selects, if SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE);  is there and I only use the first chip select, the current is 47mA. If I add the second chip select the current goes up to 80mA. If I keep both chip selects but remove SPI0_C1 = (SPI_C1_CPHA | SPI_C1_CPOL | SPI_C1_MSTR | SPI_C1_SPE);, as I said, the current goes back to 3mA
9
µTasker general / Re: SPI configs increases current absorption of 70mA
« Last post by mark on August 18, 2020, 10:59:21 PM »
Hi

Such a high current consumption is not normal. If the SPi is not actuall sending something I would not expect it to contribute much additional consumption - maximum a few 10..100uA.

It may be that one of the SPI lines is short circuiting with something; try not initialising the pins at all to see the effect of simply enabling the SPI module. If the current is then low try enabling each of the lines individually to see which one causes the problem.

Regards

Mark
10
µTasker general / SPI configs increases current absorption of 70mA
« Last post by Raffaele on August 18, 2020, 09:13:48 PM »
Hi,
I'm programming a KL03. My code has PWM, UART and a couple of interrupts. It is up and running and it only absorbs 2-3mA.
When I configure the SPI the absorbed current jumps to 75-80mA. Is this normal? Can I somehow reduce it? Even configuring and deconfiguring the SPI interface would be an acceptable solution since I use it rarely.

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;

I tried POWER_UP(4, SIM_SCGC4_SPI0) and POWER_DOWN(4, SIM_SCGC4_SPI0) and that reduces the current to half. How can I deconfigure the other peripherals _CONFIG_PERIPHERAL and _CONFIG_DRIVE_PORT_OUTPUT_VALUE?
Pages: [1] 2 3 ... 10