How implement programmable time delay ?

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

cross mob
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

I need create schema that after input pulse make output pulse after programmable time delay ( 0-10 msec).

   

This is code of it :

   

Pin_In_ClearInterrupt();
    CyDelayUs(delay);
 
    Out_Pin_Write(1);
    CyDelayUs(10);   
    Out_Pin_Write(0);

   

but I don`t want to use CyDelayUs but some hardware component.

0 Likes
21 Replies
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is a timer program that is setup for the PSOC Pioneer board.  There is a PDF in the program that explains the program. 

0 Likes
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

This example is very similar that I did with use of CyDelayUs. I search for example where I can set some value to Timer or PWM and it can make delay by hardware.

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

Usual way for these problems is to set up a timer with an isr component., start it, set your pin and in the interrupt handler stop the timer and reset the pin.

   

 

   

Bob

0 Likes
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

I have input pin  with interrupt that make start. On this interrupt  I can start timer.  How to set timer to receive delay by milliseconds ?

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

Wouldn't be too bad when you have a look into the timer's datasheet, there is an API to set the period. Timer frequency is Clock/Period. Delay is 1/Timer frequency thus 1/(Clock/Period) = Period/Clock

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

I don`t know why but only interrupt is worked. I need it without software but no one outputs is active.

   

Attached test project

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I haven't tested it, but here is a sample project that should be along the lines of what you are trying to accomplish.

   

Note: You may need to reset the timer component upon interrupt routine; You may need to double check the timer is disabled when changing the period value. (I set it to 10 ms, but you can change/configure it to different values)

0 Likes
lock attach
Attachments are accessible only for community members.
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

Sorry but it`s not work.   As I see difference between my code and your that you use start pin and one function that just set period. I made it inside component. I changed code to yours version but still no impulses from output pins of PWM. ( only interrupt work).

0 Likes
Anonymous
Not applicable

Here's some notes I have on what you changed back:

   

If you set the start pin to 1 and set it to trigger on a level, it will be constantly starting the timer, as opposed to starting the delay timer when you receive an input pulse.

   

If you wire the output of the PWM directly to the output pin you want to send the pulse on, it will just send a pulse, rather than needing to write the pulse in the ISR using software (which is what I thought you were trying to avoid?)

   

Yes, the function to rewrite the PWM period is not doing much, but it allows you to insert a PWM start/stop calls if necessary to make the operation work correctly.

0 Likes
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

you`re right but I made it just for first stage. In this stage I want to see constantly pulses with period I can change by set delay (function like you did). After I learn it and check  that it`s work I`l start it by external input pin. For now I stuck because no pulses created...

0 Likes
Anonymous
Not applicable

You can try writing a software initiated pulse into the PWM input, or use a different clock/timer to send pulses at fixed delays. Then, once you have input pulses for simulation purposes, you will be able to start testing the variable delay.

0 Likes
lock attach
Attachments are accessible only for community members.
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

I used counter to create pulses with period of 10 ms. Now I need pulses that delayed from start pulse to programmable value.

   

No impulses from PWM again. Attached corrected design.

0 Likes
Anonymous
Not applicable

When I run it on my board, it interrupts and fires the pulses from the TC_ISR just fine. I'm not sure what isn't working on your end. Are you reading the electrical output from the pins? Or just reading the value in the debugger?

   

Try putting PWM_WritePeriod(5000); on the line before PWM_Start();

0 Likes
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

It`s true. Interrupts work fine but I want  not use interrupt but hardware pulses from PWM.

0 Likes
Anonymous
Not applicable

Have you tried wiring the OV,TC,and the other PWM output pins to hardware pins to see on an oscilloscope if the PWM is outputting hardware pulses? I'm not sure what else I can help check with at this point.

0 Likes
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

Of course , as you can see I connected pins and check with scope :

   

   

0 Likes
Anonymous
Not applicable

Hmmmm; Yeah, I'm stumped. I don't see the pins firing on my test setup, and I have no idea why. Perhaps a cypress employee has some insight on doing the delayed pulse using peripherals only?

0 Likes
lock attach
Attachments are accessible only for community members.
MR_41
Employee
Employee
First like received

This can be done in hardware without any firmware intervention.  Check out the attached project.  This is configured for 2 PWM outputs with independent compare values.  The outputs are XORed.  With this setup, you can set the initial delay by configuring the first compare value, and the pulse width by setting the second compare value.

   

Initial delay = (65535 - Compare Value 1) in us
Pulsewidth = (Compare Value 1 - Compare Value 2) in us

   

Below is the scope capture of the output where I set the intial delay to 20ms and pulsewidth to 1ms.

   

   

To test the function, I have added a second PWM that runs at 1Hz and this PWM is the trigger input to the main PWM that generates the delayed pulse.  In the above scope capture, the yellow trace is this trigger signal, and the blue trace is the delayed pulse.

   

Hope this helps.

   

0 Likes
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

wow ! this is what I need. I checked and it`s work !

   

Thanks a lot !

0 Likes

You are most welcome.  Glad that it was helpful!

0 Likes
urchc_1533771
Level 5
Level 5
5 likes given First like received First like given

Hi !

   

You used  simple PWM with trigger input. In my design I use PWM in 2 modes : by trigger or continuously.

   

Unfortunately in this component not  exist API to change Trigger Mode 😞

   

How to change this PWM to TCPWM ? 

0 Likes