- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
Customer is considering measuring input pulse width using attached PDF method.
Device is PSoC4.
“reload” is executed at the timing of input signal rising edge.
And “capture” is executed at the next rising edge.
So they are considering measuring motor rotation speed by counting number of pulses of “A” period of attached file.
Is it possible to do what they want with attached PDF method?
Input signal is connected to both “reload” and “capture”.
How does PSoC4 work in this case?
Does it work in an order similar to “reload” -> “capture” -> “reload” -> “capture” .. ?
(In other words, motor rotation speed can be measured correctly.)
Or will “reload” be executed again without “capture” after “reload”?
(In other words, capture data always becomes 0 because “capture” always be executed at the same time of “reloaded” at rising edge?)
Best Regards.
Yutaka Matsubara
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi YuMa_1534086
Yes, the method suggested in the ppt works. I tried this at my end as well. The capture event occurs and the data is copied into the capture buffer before the reload event occurs.
Thanks and regards,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi YuMa_1534086
Yes, the method suggested in the ppt works. I tried this at my end as well. The capture event occurs and the data is copied into the capture buffer before the reload event occurs.
Thanks and regards,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
May be I'm saying the same thing with AH_96-san,
I think that the following 2 data transitions take place at the same timing
as (I assume that) they are implemented using sync registers.
(1) from counter register to capture register
(2) reloading the counter register
Otherwise we will get one clock less count for the capture value.
So to test it I made the following sample project with CY8CKIT-044
Schematic
(I used another PWM to emulate a motor pulse)
Pins
The serial output (Tera Term) was
The captured count was exactly the same with the PWM's period.
So I think that we can assume that those two transitions are taking place at the exact same clock edge.
main.c
==================
#include "project.h"
#include "stdio.h"
#include "tty_utils.h"
volatile int capture_flag = 0 ;
volatile uint16_t count = 0 ;
uint16_t pwm_period = 999 ;
uint16_t pwm_compare = 499 ;
uint16_t loop_limit = 10 ;
uint16_t loop_count = 0 ;
CY_ISR(capture_isr)
{
uint32_t status ;
status = TIMER_ReadStatus() ;
if (status & TIMER_INTR_MASK_CC_MATCH) {
// TIMER_ClearInterrupt(TIMER_INTR_MASK_CC_MATCH) ;
count = TIMER_ReadCapture() ;
capture_flag = 1 ;
}
TIMER_ClearInterrupt(TIMER_INTR_MASK_TC | TIMER_INTR_MASK_CC_MATCH) ;
}
void usage(void)
{
print("=== usage ===\n\r") ;
print("pwm <period> <compare> : pwm 999 499\n\r") ;
print("period <period> : period 999\n\r") ;
print("compare <compare> : compare 499\n\r") ;
print("loop <loop_limit> : loop 10\n\r") ;
print("\n\r") ;
}
void config_pwm(uint16_t period, uint16_t compare)
{
PWM_Stop() ;
PWM_WriteCounter(0) ;
PWM_WritePeriod(period) ;
PWM_WriteCompare(compare) ;
}
void report(void)
{
print("PWM ") ;
snprintf(str, STR_BUF_LEN, "period: %d ", pwm_period) ;
print(str) ;
snprintf(str, STR_BUF_LEN, "compare: %d ", pwm_compare) ;
print(str) ;
snprintf(str, STR_BUF_LEN, "Captured Count: %d\n", count) ;
print(str) ;
}
void do_command(void)
{
if (strncmp(str, "pwm",3) == 0) {
sscanf(str, "%*s %hd %hd", &pwm_period, &pwm_compare) ;
prompt() ;
} else if (strncmp(str, "period", 6) == 0) {
sscanf(str, "%*s %hd", &pwm_period) ;
prompt() ;
} else if (strncmp(str, "compare", 7) == 0) {
sscanf(str, "%*s %hd", &pwm_compare) ;
prompt() ;
} else if (strncmp(str, "loop", 4) == 0) {
sscanf(str, "%*s %hd", &loop_limit) ;
prompt() ;
} else if (strcmp(str, "run") == 0) {
loop_count = 0 ;
TIMER_Stop() ;
TIMER_WriteCounter(0) ;
config_pwm(pwm_period, pwm_compare) ;
TIMER_Enable() ;
PWM_Enable() ;
} else if (strcmp(str, "stop") == 0) {
PWM_Stop() ;
prompt() ;
} else {
usage() ;
prompt() ;
}
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
tty_init() ;
PWM_Init() ;
capture_int_ClearPending() ;
TIMER_ClearInterrupt(TIMER_INTR_MASK_TC | TIMER_INTR_MASK_CC_MATCH) ;
capture_int_StartEx(capture_isr) ;
TIMER_Start() ;
}
int main(void)
{
init_hardware() ;
splash("PWM Trigger Test") ;
usage() ;
prompt() ;
for(;;)
{
if (get_line()) {
do_command() ;
}
if (capture_flag) {
report() ;
capture_flag = 0 ;
loop_count++ ;
if (loop_count >= loop_limit) {
TIMER_Stop() ;
PWM_Stop() ;
loop_count = 0 ;
prompt() ;
}
}
}
}
===============
Lastly some more details...
While I was playing with this project,
I noticed that when I set the PWM period rather large, for example 30000 or more
the first capture value after "run" command was not correct.
But from the 2nd cycle, the values seemed to be OK.
Currently I'm assuming that this was caused by the software delay to the hardware,
so once software release the hand from the hardware, the value seems to be consistent.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Moto-san.
Thank you for your response.
Your comment is really useful.
Hari-san.
Thank you for your response.
Please send your project when you confirmed timer counter behavior, just in case?
Best Regards.
Yutaka Matsubara
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi YuMa_1534086
I have attached the sample project that I created for testing. I externally shorted the two pins to connect the PWM output to the reload and capture pin.
Regards,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hari-san.
Thank you for your support.
Best Regards.
Yutaka Matsubara