You will have to instantiate counters (in software or hardware) counting your PWM pulses for x- and y- direction. Depending on the max. pulse frequency of the PWM (less than 1kHz) you can use interrupt driven counters and shut down the PWM when the limit is reached.
Thanks for the help.
I tried using the counter but it does not work on clocks over 20khz, I need to use clock at 200khz, so I am using is component instead to count pulses. Since there are two motors, there will be 2 isr components Do I have to increase the system clock to 48mhz instead of default 24mhz ?
Is your motor step really with a frequency of 200kHz?? Can you provide a link to datasheet, please.
The motor diagram shows a usable frequency of up to 10kHz which is quite more than I expected. This would result in 2000 rpm which is quite a lot for a stepper.
//I tried using the counter but it does not work on clocks over 20khz// - But the TCPWM module datasheet says that it supports upto 48 MHz. So getting 200KHz should'nt be a problem. Where exactly did you face the problem when you tried to use it?
i Presume that you are working with Stepper motor and the drivers which suggests to have minimum pulse ON time of 5us for the driver to operate properly.
so to run the motor with heighest speed you might be expecting 20 KHz controlled clock.
i would suggest to just take 20KHz clock i/p to AND GATE and use another i/p as control input so that the operation will be fast and you can work with UART response etc just after enabling the input.
long back when PSoC 1 was popular i tired such ways. but not sure if it will work at 20Khz .
further note the input current req of the driver and check if it is matching with PSoC. if not you my try connecting configuring PSoC pins in sinc mode and providing High level form external line just as in case of I2C communication.