LabVIEW Embedded

cancel
Showing results for 
Search instead for 
Did you mean: 

duty cycle measurement

Hi all,

I need to measure duty cycle of 5 PWM signal with my LM3S8962. I precise that the PWM are not generated by the board. there are extarnal PWM and I need to measure them.

These PWM run on 50Hz. High level is between 500us and 2ms: PWM to control Brushless drivers. PWM signals are connected to GPIO

I did some trials shown below. In additions these methods can't measure width under 1ms

 

 

 read pwm.png

 

these measurement are neither precise nor stable anough. did any one have an idea about how to perform these measurements

0 Kudos
Message 1 of 10
(8,958 Views)

Are you sure about your requirements?
Do you need duty cycle or pulse width? (http://www.hooked-on-rc-airplanes.com/servo-tutorial.html)
0 Kudos
Message 2 of 10
(8,930 Views)
As the frequency is constant it's the same
0 Kudos
Message 3 of 10
(8,926 Views)

No, it's not.

 

Generally specking yes, but if my assumption is correct (you have a servo not a brushless motor) then you have to read that webpage or this one: http://www.aerodesign.de/peter/2000/PCM/PCM_PPM_eng.htmlhttp://www.aerodesign.de/peter/2000/PCM/PCM_PPM_eng.html
In RC systems the frequency could have large tolerances (e.g. 18-22ms) but pulse width not (microseconds or sub-microseconds precision).

0 Kudos
Message 4 of 10
(8,922 Views)
I have both Blushless (with drivers) and servos. yes you'r correct about pulse width
0 Kudos
Message 5 of 10
(8,918 Views)

OK, after fixing this issue let's talk about implementation.


I don't understand the previous snippets at all.
To measure those timings you have to use some timers.
The good news is Stellaris timers have input capture feature, but this is not exploited in LabVIEW (this is the bad one). If you want highest accuracy you have to write few C functions.


If couple microseconds error works fine for your application then you can use GPIO interrupts. In ISR you'll read timestamps for each edge of your pulses (read a timer value using Inline C nodes). Pulse width and periods/frequencies will result by processing those timestamps. The timer must count internal cycles with a maximum (reload value) of 2^32-1.

 

0 Kudos
Message 6 of 10
(8,895 Views)

Hi Nic,

thanks for answer

I dont need a very high precision. all what I need is to identify about 50-100 different values of the width.

 


If couple microseconds error works fine for your application then you can use GPIO interrupts.
I thought about that, However, now, I can't imagine yet how to implement this. may be this is the explaination:

 


In ISR you'll read timestamps for each edge of your pulses (read a timer value using Inline C nodes). Pulse width and periods/frequencies will result by processing those timestamps. The timer must count internal cycles with a maximum (reload value) of 2^32-1.
but I didn't really andertand what you're saying

 

 

 

 

0 Kudos
Message 7 of 10
(8,888 Views)

neil84 wrote:
I thought about that, However, now, I can't imagine yet how to implement this. may be this is the explaination:value) of 2^32-1.but I didn't really andertand what you're saying

 


OK, I am hopping the attached example will enhance understanding.
Start "arm main.vi" and then "Simulated IO pulse.vi". Modify PW and Period on "Simulated IO pulse.vi" front panel and watch results on "arm main.vi" and Output Window.
See "Manage Interrupts" (Timer0 and GPIO D). Both interrupts call "GPIO Pulse ISR.vi" but only pin 4 of GPIOD is used in this example. The application uses a global cluster for foregroud/backgroud communication.

 

Why GPIO_IN_D4 is chosen here?

 

0 Kudos
Message 8 of 10
(8,863 Views)

Hi Nic,

I'm not able to try your example because of my debug problem.

I'll try tomorrow on board.

So if I understand: in GPIO Pulse ISR, Tvalueis incremented every timer interruption and it's affected to update until GPIO_D4 is true. Am I correct?

 


Why GPIO_IN_D4 is chosen here?


It's an arbitrary choice.

 

In fact, I need to measure 6 PWM widths so when designing my sensor card I provided some GPIO: PC4-7 and PB4-6

To perform all the 6 measurement, I need to duplicate GPIO Pulse ISR.vi 6 times, Am I correct?

thanks

 

0 Kudos
Message 9 of 10
(8,856 Views)

 


neil84 wrote:

So if I understand: in GPIO Pulse ISR, Tvalueis incremented every timer interruption and it's affected to update until GPIO_D4 is true. Am I correct?


 

No, Tvalue is the current value of Timer0 A register (TAR). "GPIO Pulse ISR.vi" is processing only "GPIO D" events. Timer0 interrupts are directed to the same VI just to make LabVIEW happier (if an interrupt is used then it requests an ISR VI). Actually that interrupt is not enabled because we don't need it at all - Timer0 is configured to count down from 0xFFFFFFFF (-1) down to 0, repeating the cycle indefinetely.


The algorithm is very simple:
1. A rising edge interrupt arrives – Tvalue is saved to Trise (i.e. 1025000)
2. A falling edge also trigger the interrupt and Tvalue is saved to Tfall (i.e. 1000000)
3. On the next rising edge Trise gets a new value (i.e. 525000), but prior saving it we compute the period. Also a counter ("update") is used to signal the main program there are new results available.


With the numeric values given above:

PW=1025000-1000000 = 25000

and

period = 1025000-525000 = 500000.

 

Of course, to transform all to microseconds, the number of cycles has to be devided by frequency (in MHz):
PW[us] = 25000/50 = 500 us;

period[us] = 500000/50 = 10000 us.

 

Note: in my example the results are not correct when update==1; that's why "arm main.vi" uses those values only after "update" member is greater than 1 (after second pulse).


neil84 wrote:
 

Why GPIO_IN_D4 is chosen here?


It's an arbitrary choice.

 


Take a look into microcontroller's datasheet. You'll find more about Stellaris timers, including an answer to my question, and probably figuring out a method to improve accuracy.


neil84 wrote:
 

In fact, I need to measure 6 PWM widths so when designing my sensor card I provided some GPIO: PC4-7 and PB4-6

To perform all the 6 measurement, I need to duplicate GPIO Pulse ISR.vi 6 times, Am I correct?

thanks



You'll not need 6 ISR VIs. However, a single ISR can be assigned to one GPIO port.

For the two ports you have two options:

- use two ISR VIs,

- use one VI for all - just add more cases in "GPIO Pulse ISR.vi" (see the vector and param terminals).

 

Message Edited by NicB on 10-20-2009 04:30 AM
0 Kudos
Message 10 of 10
(8,841 Views)