- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It`s true. Interrupts work fine but I want not use interrupt but hardware pulses from PWM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Of course , as you can see I connected pins and check with scope :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
wow ! this is what I need. I checked and it`s work !
Thanks a lot !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are most welcome. Glad that it was helpful!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?