cypress counter

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

cross mob
MaSa_4380396
Level 1
Level 1

hi everyone

i have a one sensor that produces square wave.I want the counter to count on the positive edge of the square wave but i didnt start counter.i use cykit 049 4200.

I will be glad if you help me.I would like a sample project if possible.

Adsız.png

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

> Basically, how to run a counter.

Unfortunately how to run a counter is different depending on the component and its configuration.

So we need to refer to the datasheet of each component to check how.

The datasheet is accessible via the [Datasheet] button shown in the configuration dialog

or in the bottom part of the Component Catalog when select a component.

In my sample, I used "Timer Counter" with "start", "reload" and "capture" pin.

And in the configuration I set the Mode of "reload" and "start" Rising edge,

so when SIG_IN rises (LOW -> HIGH), the timer gets reloaded and started.

Meantime, I set the Mode of "capture" Falling edge,

so when SIG_IN falls (HIGH -> LOW) the Timer captures the current count

as the captured value.

010-Timer_Config.JPG

moto

View solution in original post

0 Likes
4 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Without giving a code-example (I do not have any -049-42xx kits) I can give you some suggestions.

At first: Try to get a CY8CKIT-043. Programming AND DEBUGGING(!!) will be much easier.

Use a TCPWM component configured as timer, interrupt on capture falling edge with count input.

Connect capture, count and your signal to measure together.

Provide a clock to count.

Provide an interrupt handler where you stop the counter, read the captured value,read the status to clear the interrupt,set counter to zero and start again.

Not complicated, just a handful of code lines.

Bob

0 Likes
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 this with CY8CKIT-049-42xx but I cheated by using KitProg from CY8CKIT-043 as Bob-san suggested.

So if you will try my project with plain CY8CKIT-049-42xx, please make sure that you have bootloader included

or you have other debugger like MiniProg3 or KitProg.

IMG_3725.JPG

My schematic looks like below.

The upper half is the measurement circuit.

The lower PWM is a test signal generator.

I tested the circuit by jumper SIG_IN(P1[3]) and SIG_OUT(P1[2]).

001-schematic.JPG

Pin assignment is

002-pin-list.JPG

main.c

================

#include "project.h"

#include "stdio.h"

volatile uint16_t value ;

volatile int capture_flag = 0 ;

char str[128] ; /* print buffer */

void print(char *str)

{

    UART_UartPutString(str) ;

}

CY_ISR(capture_isr)

{

    if (Timer_GetInterruptSource() == Timer_INTR_MASK_CC_MATCH) {

        value = Timer_ReadCapture() ;

        Timer_Stop() ;

        PWM_Stop() ;

        Timer_ClearInterrupt(Timer_INTR_MASK_CC_MATCH) ;  

        capture_flag = 1 ;

    } else {

        Timer_ClearInterrupt(Timer_GetInterruptSource()) ;

    }

}

int main(void)

{

    uint16_t i = 100 ;

  

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

  

    sprintf(str, "Counter Test (%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

  

    Capture_INT_ClearPending() ;

    Timer_ClearInterrupt(Timer_INTR_MASK_CC_MATCH) ;

    Capture_INT_StartEx(capture_isr) ;

    Timer_Start() ;

  

    PWM_WriteCompare(i) ;

    PWM_Start() ;

    for(;;)

    {

        if (capture_flag) {

            sprintf(str, "%d: %d\n",i,  value) ;

            print(str) ;

            capture_flag = 0 ;

            CyDelay(1000) ;

            i = (i + 10) % PWM_ReadPeriod() ;

            PWM_WriteCompare(i) ;

            Timer_WriteCounter(0) ;

            Timer_Start() ;

            PWM_Start() ;

        }

    }

}

================

The Tera Term log was below.

The number left is the compare value for the PWM (100kHz) (signal generator)

The number right is the measured value by 1MHz clock.

000-TeraTerm-log.JPG

moto

0 Likes

Basically, how to run a counter.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

> Basically, how to run a counter.

Unfortunately how to run a counter is different depending on the component and its configuration.

So we need to refer to the datasheet of each component to check how.

The datasheet is accessible via the [Datasheet] button shown in the configuration dialog

or in the bottom part of the Component Catalog when select a component.

In my sample, I used "Timer Counter" with "start", "reload" and "capture" pin.

And in the configuration I set the Mode of "reload" and "start" Rising edge,

so when SIG_IN rises (LOW -> HIGH), the timer gets reloaded and started.

Meantime, I set the Mode of "capture" Falling edge,

so when SIG_IN falls (HIGH -> LOW) the Timer captures the current count

as the captured value.

010-Timer_Config.JPG

moto

0 Likes