ctimer match value and pre-scalar adjustment for 250 khz frequwncy

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

ctimer match value and pre-scalar adjustment for 250 khz frequwncy

2,842 Views
sachinn434
Contributor I

hi everyone I am using lpc54s018 evk board 

I need to know what is the pre scalar value and match value should mention for 250KHZ 

I am using the ctimer match interrupt operation so I am facing an issue 

I need to generate 25 pulses with gpio toggle after stop ctime in call back function 

 

thanks in advance

 

0 Kudos
11 Replies

2,695 Views
sachinn434
Contributor I

hi sir,

can  please tell me sdk version your using  i am using 2.13 version

because i am not getting as you described in last reply

Regards,

sachin

 

0 Kudos

2,811 Views
Petr_H
NXP Employee
NXP Employee

Hi, 

I'm sorry, but it's not clear what do you need to achieve. Please add more details, what signals you need to generate or measure.

Do you need interrupt callback with frequency 250 kHz? I fear that it's too high and it won't work properly...

Do you need to generate those 25 pulses always (every period)?

regards

Petr Hradsky

Config Tools Team

 

0 Kudos

2,776 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

You want to toggle a GPIO so that the GPIO clock frequency is 250kHz, so the CTimer interrupt frequency has to be 500KHz.

The CTimer interrupt frequency is 500KHz.
For the CTimer, The Prescaler*Match value=12000000/500000=24.

In the case, the prescaler can be 1, the match can be 24.

You can use the code:
/* Configuration 0 */
matchConfig0.enableCounterReset = true;
matchConfig0.enableCounterStop = false;
matchConfig0.matchValue = 24;
matchConfig0.outControl = kCTIMER_Output_Toggle;
matchConfig0.outPinInitState = false;
matchConfig0.enableInterrupt = true;

/* Configuration 1 */
matchConfig1.enableCounterReset = true;
matchConfig1.enableCounterStop = false;
matchConfig1.matchValue = 24;
matchConfig1.outControl = kCTIMER_Output_Toggle;
matchConfig1.outPinInitState = true;
matchConfig1.enableInterrupt = true;

CTIMER_RegisterCallBack(CTIMER, &ctimer_callback_table[0], kCTIMER_MultipleCallback);
CTIMER_SetupMatch(CTIMER, CTIMER_MAT0_OUT, &matchConfig0);
CTIMER_SetupMatch(CTIMER, CTIMER_MAT1_OUT, &matchConfig1);

 

Hope it can help you

BR

XiangJun Rong

0 Kudos

2,753 Views
sachinn434
Contributor I

Hi sir,

thanks for the reply  based on that I changed  the presale is 1 and the match value is 24

now i am getting 120KHZ but i am not able to stop the clock after 25 pulses because

i need to take 25 pulse bit value and the next transmission delay like ctimer tp(pause period) so how i can achieve that one if you have any idea please share me 

 

PRINTF("SSI INTERFACE USING GPIO\r\n");
srcClock_Hz = CTIMER_CLK_FREQ;
PRINTF("CTIMER_CLK_FREQ %d\r\n",CTIMER_CLK_FREQ);
CTIMER_GetDefaultConfig(&config);

config.prescale = 1;// 1ms tick

// timerClock = srcClock_Hz / (config.prescale+256);

PRINTF("timerclock %d\r\n",timerClock);

CTIMER_Init(CTIMER, &config);
matchConfig.enableCounterReset = true;
matchConfig.enableCounterStop = false;
matchConfig.matchValue = 24;//timerClock/480;//timerClock/2; //timerClock/0.024;//CTIMER_CLK_FREQ;//CTIMER_CLK_FREQ/4000000;
PRINTF("matchValue %d\r\n",matchConfig.matchValue);
matchConfig.outControl = kCTIMER_Output_Toggle;
matchConfig.outPinInitState = true;
matchConfig.enableInterrupt = true;

 

CTIMER_SetupMatch(CTIMER, CTIMER_MAT_OUT, &matchConfig);

CTIMER_RegisterCallBack(CTIMER, &ctimer_callback_table[0], kCTIMER_SingleCallback);

CTIMER_StartTimer(CTIMER);

 

here  i am not able to stop that one 

static uint32_t count = 0;
if (++count >=1) {
// Disable match interrupt and stop ctimer
CTIMER_StopTimer(CTIMER);
CTIMER_DisableInterrupts(CTIMER, kCTIMER_Match0InterruptEnable);

delay();//delay();delay();delay();//delay();delay();delay();delay();delay();delay();
//delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();
// delay();delay();delay();delay();delay();delay();delay();delay();delay();delay();

CTIMER_EnableInterrupts(CTIMER, kCTIMER_Match1InterruptEnable);
CTIMER_StartTimer(CTIMER);

}

//PRINTF("k=%d\n",k);
if(count)
{

databuf[k--] = GPIO_PinRead(GPIO, BOARD_PORT, BOARD_DATA_PIN);
PRINTF("databuf=%d\n",databuf[k]);
PRINTF("count=%d\n",count);
}

 

 

thanks 

0 Kudos

2,788 Views
sachinn434
Contributor I

Hi,

please follow the below-attached doc

0 Kudos

2,793 Views
sachinn434
Contributor I
Hi,
Thanks for your reply I am trying to achieve SSI Standard protocol using the gpio toggle with the Ctimer match register but i am not getting how to set
frequency of 250KHZ and it should generate an interrupt for every clock pulse
in standard SSi 25bit pattern, i need to collect 25 bits and after 25 pulses I need to pause the Ctimer with some delay and again repeat the above condition
it is basically SSI driver i am trying to develop through gpio so please help me if you have any idea about these
0 Kudos

2,726 Views
Petr_H
NXP Employee
NXP Employee

Hi,

So if I understand it correctly, you need to transfer data via SSI protocol.

From the attached document it seems it's a synchronous serial communication so I think it would be much more convenient to use FlexComm in SPI mode that should be able to do it for you much more easily instead of handling it via GPIO.

You can simply configure it in MCUXPresso Peripherals tool like this:

Petr_H_3-1678187607167.png

I've tried to set it according to your specification - 250 kHz bitrate and 5 bit length of data. This should allow to send the mentioned 25 bits as 5 characters that are 5 bits long.

Please note that you can use any FlexCom that you can route in Pins tool to the pins you need, I've used FlexCom5 as example. 

I've set there Mode: Transfer, which means that the driver initialization is generated in transfer mode, which is simplest to use.

Then you will be able to send the data using the  SPI_MasterTransferBlocking function.

You can also find example in SDK in \driver_examples\spi\polling_b2b_transfer\master\spi_polling_b2b_transfer_master.c 

Regards

Petr Hradsky 

Config Tools Team

 

 

0 Kudos

2,717 Views
sachinn434
Contributor I

hello sir,

once again thank you,

I need to write SSI driver using gpio toggle  because i am using  LPC54S018 nxp evk board so this board is not supporting  SSI protocol and flexio  so thats why i am decided to develop SSI driver so every thing is working fine but match value and prescale i am struggling here because asper the document  i need to set around 250KHZ frequency and generate interrupt at every clock pulse after 25 clock pulse i need to pause ctimer for delay and again repeat the same procedure 

0 Kudos

2,682 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

As Petr said you can use spi module of LPC54S018 to simulate the SSI, all FlexCommx module can function as SPI. 

If you use GPIO to simulate SSI, it is difficult.

Hope it can help you

BR

XiangJun Rong

 

0 Kudos

2,710 Views
Petr_H
NXP Employee
NXP Employee

The configuration that I described is for LPC54S018 and should be applicable for EVK board so I still think that SPI should be usable to emulate SSI. 

Regards

Petr Hradsky

 

0 Kudos

2,818 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

As you know that the CTimer use Async APB clock as clock source.

1)Ctimer driving clock

With the code:

/* Enable the asynchronous bridge */
SYSCON->ASYNCAPBCTRL = 1;

/* Use 12 MHz clock for some of the Ctimers */
CLOCK_AttachClk(kFRO12M_to_ASYNC_APB);

The CTimer driving clock will be 12MHz.

 

2)CTimer interrupt frequency:

As the following red line, the match register with enableCounterReset=true; will determine the interrupt frequency. For the case that there are multiple match register with enableCounterReset=true;  the match register with minimum value will determine the interrupt frequency.

The interrupt frequency =

ASYNC_APB/[(Prescaler value)*match register value]

For the example code in SDK package

The interrupt frequency =12MHz/(1*(CTIMER_CLK_FREQ / 2))=2

the CTIMER_CLK_FREQ is 12000_000, the same as the ASYNC_APB clock frequency.

The Prescaler value is 1.

The CTimer interrupt frequency is 2Hz in the SDK example.

 

/* Configuration 0 */
matchConfig0.enableCounterReset = true;
matchConfig0.enableCounterStop = false;
matchConfig0.matchValue = CTIMER_CLK_FREQ / 2;
matchConfig0.outControl = kCTIMER_Output_Toggle;
matchConfig0.outPinInitState = false;
matchConfig0.enableInterrupt = true;

/* Configuration 1 */
matchConfig1.enableCounterReset = true;
matchConfig1.enableCounterStop = false;
matchConfig1.matchValue = CTIMER_CLK_FREQ / 2;
matchConfig1.outControl = kCTIMER_Output_Toggle;
matchConfig1.outPinInitState = true;
matchConfig1.enableInterrupt = true;

CTIMER_RegisterCallBack(CTIMER, &ctimer_callback_table[0], kCTIMER_MultipleCallback);
CTIMER_SetupMatch(CTIMER, CTIMER_MAT0_OUT, &matchConfig0);
CTIMER_SetupMatch(CTIMER, CTIMER_MAT1_OUT, &matchConfig1);

 

Hope it can help you

BR

XiangJun Rong

0 Kudos