- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you concerned with the duty cycle of the PWM signal or the period/frequency ?
If the latter attached is an example of a freq counter, Period = 1 / Freq or vice versa.
If you need the duty cycle then use a timer to capture high time, and use it again to
capture low time.
Regards, Dana.
- 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
- 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
Actually might be better to use a counter because it has an enable.
So feed PWM signal to counter enable. Counter clock will determine
resolution of measurement. When enable goes high, counter starts
counting down (you preloeaded it with full scale, full scale is 2**n - 1)
then when enable goes low read counter, subtract from full scale, and that
is counts(time) PWM was high. You can do this by interrupt or polling, freq
of PWM may determine which method. Also reload counter when enable is
low.
Now you have to measure low, so could use another counter whose enable
is inverted from PWM. Same as above but measures low time/counts of PWM.
Or use one counter, running countinuously. When PWM edge goes high, use pin
ISR to read counter, that subtracted from full scale is high period. Counter keeps
going. Use another pin also connected to PWM signal, set for falling edge ISR.
When ISR triggers read counter again, subtract that from earlier reading, you have
high time. Also this is the start of low time, so next time pin ISR edge goes high,
read counter and subtract from falling edge reading, that becomes low time.
As you can see, various ways of doing this.
What is the range of PWM period you have to measure ? Resolution of measurment ?
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An error in prior post -
Or use one counter, running countinuously. When PWM edge goes high, use pin
ISR to read counter, that subtracted from full scale is high period. Counter keeps
going. Use another pin also connected to PWM signal, set for falling edge ISR.
When ISR triggers read counter again, subtract that from earlier reading, you have
high time. Also this is the start of low time, so next time pin ISR edge goes high,
read counter and subtract from falling edge reading, that becomes low time.
Should be
Or use one counter, running continuously. When PWM edge goes high, use pin
ISR to read counter. Counter keeps going. Use another pin also connected to PWM
signal, set for falling edge ISR. When ISR triggers read counter again, subtract that
from earlier reading, you have high time. Also this is the start of low time, so next time
pin ISR edge goes high, read counter and subtract from falling edge reading, that
becomes low time.
If you are pin limited, place two buffers, and set them to gen ISR on opposing edges.
Regards, Dana.
- 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
- 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 enable goes low read counter, subtract from full scale, and that is counts(time) PWM was high. You can do this by interrupt or polling” What is polling?
Polling is repeatedly reading a HW status, like a pins value in this case. Essentially a do or while
loop.
I can use the global interrupt yes, on falling edge, is there any other way to get an interrupt when the input to the counter gets low?
Yes, place a buffer in digital array, route PWM in to its input, and set up its ISR for falling edge
of PWM input.
And you cannot reset the counter, so after first read you are stuck at (lets say 8bit counter) some number between 255-0. This above mentioned way to di it is what I do, but since I cant reset the counter back to 255, I have to use this big code to do it. Cant cypress implement a function to reset counters ^^ or being able to change the value. I only need to measure the duty cycle.
There is a simple API in counter datasheet to reload the period.
Also for what I understand, there is only 1 interrupt function for all inputs. So that if I use the falling edge method (which is ok) then I shouldn’t be using other interrupt´s on any other inputs, because they trigger the same function right? Thanks in advance
Via register writes you can change a pins ISR response from rising to falling edge. You find
this in the register TRM for the part you are using. For example see below for a 29466.
Regards, Dana.
- 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
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The forum software has an issue that sometimes a small window
appears and thats all you get to type into. I find using Firefox that
most of the time this does not occur, and when it does, clear all history
and reload page, that usually fixes problem.
Regards, prior posts, I think if you run counter continuously, you will not
have to relaod counter. You just keep reading. The only issue you have
is to test for rollover. Say counter is at 100 (last reading), next measurement
is at 150, that means counter rolled over, so your answer = last reading +
256 - new reading. For 8 bits.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What is the range of PWM period you have to measure ? Resolution of measurement ?
If you do not have a scope signal verification, insuring PWMunknown is clean to make
measurements on difficult.
If you have a pc, you have a signal generator and oscilloscope, low speed, via use of
your sound card. YOU HAVE TO BE VERY CAREFUL WITH SIGNAL LEVELS BEING
INPUT TO SOUND CARD, USE A R DIVIDER TO MAKE SURE SIGNAL IS SMALL TO
PROTECT YOUR SOUND CARD INPUT. Same with output.
http://www.zeitnitz.de/Christian/scope_en
http://www.radio.imradioha.org/PC_Based_Test_Gear.htm
You can slow down signals so they fall in range of PC Scope, then raise them
after you have finished debug.
Regards, Dana.