Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Monitoring a PWM output sensor


IslandMan Jul 21, 2009 09:11 AM

Greetings fellow board members,

I have an absolute shaft encoder with a 12 bit PWM output from US Digital. Does anyone have any experience measuring such a device with a CR1000.

Link to device:
http://usdigital.com/products/encoders/absolute/rotary/shaft/ma3/

I've been looking through the CR1000 help for something obvious but didn't spot anything right off the bat.

Any help would be appreciated.
Thanks,
IslandMan


Sam Jul 21, 2009 10:36 PM

IslandMan,

As far as I can tell, we do not have a canned instruction for measuring the duty cycle of a signal. However, you should be able to use the "TimerIO" function and two digital channels to measure 1)period and 2)time on in order to calculate duty cycle. I HAVE NOT TESTED this, but I figured in the absence of any other responses, maybe this post will give you an idea.

'Measure period on channel 1
TimerIO(Per,1,1,0,0)

'Measure Time On on channel 2 (relative to edge detection
'of channel 1
TimerIO(TOn,0,3,0,0)

'Calculate Duty Cycle
DutyC = TOn / Per

'Calculate position
'From manual
'http://usdigital.com/products/encoders/absolute/rotary/shaft/ma3/

x = ((DutyC * 4098))-1

If x = 4096 Then
x = 4095
EndIf

Sam


IslandMan Jul 22, 2009 10:25 AM

Hi Sam,
Appreciate the input. I'll give this a try and post results.
Thanks,
IslandMan


Sam Jul 22, 2009 02:44 PM

IslandMan,

I had a response from Andrew S. who ran with the posted code. He had experience using TimerIO with the CR5000. He suggested changes, as he actually tested it with a pulse generator. Thanks Andrew.


Public pwmdat(2), position, dutycycle

Alias pwmdat(1)= period
Alias pwmdat(2)= t_on

BeginProg
Scan (1,Sec,0,0)

'Measure period on channel 1, and time till falling edge on channel 2
'NOTE: the sensor is connected to both C1 and C2 with a link

TimerIO(pwmdat(),00000001,00000031,0,0)

'Calculate position
'From manual
'http://usdigital.com/products/encoders/absolute/rotary/shaft/ma3/
'From the data sheet
'Position = ((t on * 4097) / (t on+ t off)) -1
'period equals ton+toff. So to scale 0-4096 the formula is:

Position = ((t_on * 4097) / (period)) -1

'or
dutycycle = t_on / period
'Position = (dutycycle * 4097) -1


NextScan
EndProg

* Last updated by: Sam on 7/22/2009 @ 9:19 AM *


IslandMan Jul 22, 2009 03:20 PM

Sam/Andrew S.

Thanks for the all the help, it's working fine. Here's what I wound up with, same as above except converted to 0-360 Degrees. I love working with this board, I really learn a lot from here.

'Declare Public Variables
Public MA3(2), Position
Alias MA3(1) = Tot
Alias MA3(2) = Ton

BeginProg
Scan (1,Sec,0,0)
'Read MA3 Sensor on C5,C6
TimerIO (MA3(),00010000,00310000,0,0)
'Calculate Position in Degrees
Position = (((Ton * 4097)/(Tot))-1) * 0.087869
NextScan
EndProg

Regards,
IslandMan

Log in or register to post/reply in the forum.