Miac Reading Encoder Signal

For MIAC users to discuss projects, applications, and any other issues related to the MIAC unit.

Moderators: Benj, Mods

Post Reply
chris_muller
Posts: 2
Joined: Sun May 18, 2014 2:23 pm
Contact:

Miac Reading Encoder Signal

Post by chris_muller »

Hi Everyone, I really need help here, I don't know if I a missing something, or am just making mistakes due to inexperience.

I currently have a brushless motor with encoder setup, and I am trying to read the pulses coming from the encoder. But I am not reading the pulses reliably at all. I have attached my code for reference.

The brushless motor is driven by an analogue out signal from the Miac Advanced module, pin T16, connected to the analogue in pin on a Escon 50/5 driver which controls the motor. according to the Escon software the driver is receiving a input analogue in signal of 0.75V which converts to 260rpm due to how the Escon driver is setup. I am using pin T1 and T2 as digital outputs to switch motor on and specify direction of rotation, respectively.

The encoder itself is a Heidenhain incremental encoder (ROD 426 5000 01) with 5000 pulses per revolution. Connected (for now) to the motor through a pulley and belt setup. Assuming no slippage on the belt and a gear ratio of roughly 27,5 : 32,5 (diameters of the pulleys motor : encoder). Output is TTL from what I can ascertain. This is the only working encoder I have, thus for now I will have to make do. 5V supply voltage. Pulse A connected to Miac Advanced module T3 and Pulse B to T4.

thus the following calcs apply:
encoder rpm = 27,5/32,5 * 260 = 220rpm
pulse frequency = 220 rpm * 5000 pulses per revolution / 60 seconds per minute = 18,33333 kHz

I am using an interrupt to check the state of pulse A and compare it with the previous state of pulse A. If pulse A is high and previous pulse A was low, than I have crossed the rising edge of the encoder pulse, thus increment ++ my count.

Interrupt frequency is 46,875 kHz according to Flowcode software. Thus the interrupt frequency is higher than the pulse frequency according to my understanding. eventually I would like the speed to go up in the order of 3000 to 4000 rpm, but I fear the pulse frequency will be too high for my interrupt frequency.
I am using version 5 as version 6 doesn't (or did not) support 12 bit ADC conversion which we will need later.

Some miscellaneous notes:
1) total distance is set to 0.01mm, which will give me 10 pulses before stopping the motor. Because I am not reading the pulses reliably it takes a long time (in the order of minutes) to get to ten pulse counts.
2) I am defining LEDs to take the place of digital outputs, and switches as digital inputs in my Flowcode program. The LEDs define the motor on/off and direction of rotation signals, while the switches take the place of my incoming encoder signals.
3) pulse to complete is defined as a Long variable, as this will give me sufficient counts to eventually accommodate a distance travelled of 2metres.

I have referenced forum posts and other help sources such as "digital frequency counter", "motor5" and eblocks rotary encoder examples. The attached is the culmination of all my research, trail and error, research, trail and error, etc. etc. If there was something I missed, or something else I should have done, please let me know.

If required I can send pictures of my test setup.

Thank you in advance.
Chris
Attachments
Analogue Motor Control with pulse count 0.6.fcf
(18.63 KiB) Downloaded 427 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Miac Reading Encoder Signal

Post by LeighM »

Hi Chris,

The biggest issue here is that the MIAC and the Advanced Module communicate via the CAN bus.
This means that the fastest sample rate for reading the T terminals of Advanced Module would be in the region of 2KHz, which is far too low for the encoder.
Is it possible for you to connect the encoder directly to the MIAC inputs?
(Also, you would most likely need to level shift up from 5v in that case)

Regards,
Leigh

chris_muller
Posts: 2
Joined: Sun May 18, 2014 2:23 pm
Contact:

Re: Miac Reading Encoder Signal

Post by chris_muller »

Hi Leigh,

Thanks, I had a hunch I was missing something simple. I will try again and connect it to the Miac unit itself, with some sort of pull-up.

Kind regards,
Chris

Post Reply