Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 4 Forum Discussions

auwi_3091191
Level 1
Level 1
5 questions asked 5 replies posted 10 sign-ins

I need to generate a 256Hz clock that I can access in firmware so I can execute some functions on the timer tick. I've looked at several examples and videos but I am still not sure how to access the clock in firmware. Any help would be greatly appreciated!

0 Likes
1 Solution

auwi,

I've created a very small project that causes an interrupt on every rising edge of the 256 clock.  I've attached the project to this post.

Inside the ISR (called tick_isr) you place your code to service the ISR.

I do not have the PSoC4 module you are targeting so I could not test it.  However it is very simple and should work.  Try it.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
7 Replies
Fayne_Meng
Level 4
Level 4
100 sign-ins First like received 10 likes given

Hi,

   Do you want to make a timer ? Clock_4 and Timer_nms folders are generated related functions that you can call yourself . For details, see the screenshot below and see the Datasheet of component:

11.png22.png44.png33.png

 

 

0 Likes

I've configured a timer to run off of a 2.56kHz clock (I got errors trying to do a 256 Hz clock). From my understanding I need to have this timer send an interrupt every 10 cycles (2560/256 = 10), call my functions, clear the interrupt, and then reload the timer so it starts over. Is that correct?

timer_1.png

 

0 Likes

Hi,

    You can change Prescaker 、Period and Compare in the componment or the functions generated by the component.As you described, you need to calculate the exact time.For example,the following code is my timed n ms example, you can refer to it.

void Timer_User_Init(void)
{
/* 初始化nms定时器模块 */
Timer_nms_Start();
/* 停止nms定时器 */
Timer_nms_Stop();
/* 更改定时器周期模块初始化默认是时钟1M,1分频,period=999,模块默认定时时间:1/1M x 1000 = 1ms*/
Timer_nms_WritePeriod(uint32 period);
/* 使能nms定时器 */
Timer_nms_Enable();
/* 使能nms定时器中断 */
Timer_nms_ISR_StartEx( InterruptHandler_nms );

}

CY_ISR( InterruptHandler_nms )
{
uint32 InterruptHpn_nms;
/* 检查中断源和清中断 */
InterruptHpn_nms = Timer_nms_GetInterruptSourceMasked(); //timer定时nmS
if ( InterruptHpn_nms == Timer_nms_INTR_MASK_TC )
{
Timer_nms_ClearInterrupt( Timer_nms_INTR_MASK_TC );
/* Place your application code here. */

}
}

屏幕截图 2022-05-05 094201.png

0 Likes
Len_CONSULTRON
Level 9
Level 9
500 solutions authored 1000 replies posted 750 replies posted

auwi,

What is the PSoC4 part number you plan to use?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

I am using the CYBLE-014008-00 chip on a custom built PCB.

0 Likes

auwi,

I've created a very small project that causes an interrupt on every rising edge of the 256 clock.  I've attached the project to this post.

Inside the ISR (called tick_isr) you place your code to service the ISR.

I do not have the PSoC4 module you are targeting so I could not test it.  However it is very simple and should work.  Try it.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Thank you! Everything is running properly.

0 Likes