PSOC 101: Lesson 9 Timer example for PSOC 5LP

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

cross mob
Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hello,


I have been trying to configure the TImer component in the PSOC Creator library to implement the functionality mentioned in the PSOC 101: Lesson 9 Timer, but can't seem to properly configure the Timer component properly.

I know the PSOC 4 has a special TCPWM component, which is used in the tutorial. 
Can anyone help me how to bring the same functionality of the Lesson 9 with PSOC 5LP and give some explaination for the same?

Looking forward to get some insight.

Regards,
Yash

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried with CY8CKIT-059 .

I hope this could be somewhat you wanted...

 

And I found  a few traps 😉

(1) First of all there is no such thing TCPWM, so use Timer and PWM

(2) Timer is "Down only" counter

(3) 10KHz Timer clock may be too fast for those slow people, including me.

      So I changed it to 1KHz.

(4) Similarly I changed the period of PWM to 65535 to make it more forgiving.

 

schematic

001-schematic.JPG

PWM config

003-PWM_Settings.JPG

Timer config

004-Timer_Settings.JPG

Pins

002-Pins.JPG

main.c

#include "project.h"

uint16_t pwm_period = 0xFFFF ;

CY_ISR(Timer_Int_Handler)
{
    int32_t counter ;
    
    counter = 0xFFFF - Timer_ReadCapture() ;

    if ( counter > pwm_period ) {
        counter = pwm_period ;
    }
    
    PWM_WriteCompare(counter) ;
    
    Timer_ReadStatusRegister() ;
    Timer_WriteCounter(0) ;
}

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    PWM_Start() ;
    Timer_Start() ;
    pwm_period = Timer_ReadPeriod() ;
    Timer_Int_StartEx(Timer_Int_Handler) ;

    for(;;)
    {
        /* Place your application code here. */
    }
}

 

moto

View solution in original post

1 Reply
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I tried with CY8CKIT-059 .

I hope this could be somewhat you wanted...

 

And I found  a few traps 😉

(1) First of all there is no such thing TCPWM, so use Timer and PWM

(2) Timer is "Down only" counter

(3) 10KHz Timer clock may be too fast for those slow people, including me.

      So I changed it to 1KHz.

(4) Similarly I changed the period of PWM to 65535 to make it more forgiving.

 

schematic

001-schematic.JPG

PWM config

003-PWM_Settings.JPG

Timer config

004-Timer_Settings.JPG

Pins

002-Pins.JPG

main.c

#include "project.h"

uint16_t pwm_period = 0xFFFF ;

CY_ISR(Timer_Int_Handler)
{
    int32_t counter ;
    
    counter = 0xFFFF - Timer_ReadCapture() ;

    if ( counter > pwm_period ) {
        counter = pwm_period ;
    }
    
    PWM_WriteCompare(counter) ;
    
    Timer_ReadStatusRegister() ;
    Timer_WriteCounter(0) ;
}

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    PWM_Start() ;
    Timer_Start() ;
    pwm_period = Timer_ReadPeriod() ;
    Timer_Int_StartEx(Timer_Int_Handler) ;

    for(;;)
    {
        /* Place your application code here. */
    }
}

 

moto