- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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]).
Pin assignment is
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.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Basically, how to run a counter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
moto