Author Topic: Arduino and interrupts with rotary encoder.  (Read 1566 times)

0 Members and 1 Guest are viewing this topic.

Offline medical-nerdTopic starter

  • Regular Contributor
  • *
  • Posts: 198
  • Country: gb
  • What's that coming over the hill?
Arduino and interrupts with rotary encoder.
« on: June 15, 2018, 11:39:33 pm »
Hiya

I want to control a Si5351a dds using a 200ppr optical rotary encoder. All the previous examples I have seen just use the bog standard 16ppr mechanical encoders.
I have looked at the options and using interrupts seem to be the best  - does anyone know if an arduino can handle the speed of such an encoder?
Paul's optimised library seems ideal but using a teensy 3.2 just for this looks like overkill - I'd rather just use a nano clone but its not clear if this
library is just for teensy . Any advice before I start?

Cheers
« Last Edit: June 16, 2018, 01:00:14 pm by medical-nerd »
'better to burn out than fade away'
 

Offline obiwanjacobi

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Arduino and interrupts with rotary encoder.
« Reply #1 on: June 17, 2018, 06:17:52 am »
Is a Si5351a a motor? (couldn't find it on a quick search)
Depends how fast the decoder will be spinning (rpm of the motor) and what amount of work needs to be done in the ISR (keep it short) and the clock speed of the processor - for a standard Nano that would be 16MHz.

My gut feeling says it should be okay.
My advice would be to make the investment of a Arduino Nano and simply go try stuff and measure.

[2c]
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Arduino and interrupts with rotary encoder.
« Reply #2 on: June 17, 2018, 07:30:12 am »
Yes you should have no problem utilizing a arduino nano to control your DDS module. I used one to control a AD9850 DDS module several years ago. You can even utilize/configure your 200 ppr encoder to generate either 200, 400, or 800 interrupts per step by utilizing either a single user interrupt pin or both user interrupt pins and either 'falling' or 'change' interrupt triggering.
« Last Edit: June 17, 2018, 07:35:12 am by retrolefty »
 

Offline GeorgeOfTheJungle

  • Super Contributor
  • ***
  • !
  • Posts: 2699
  • Country: tr
Re: Arduino and interrupts with rotary encoder.
« Reply #3 on: June 17, 2018, 07:53:11 am »
You need to time the ISR in clock cycles and see, because at say 3000 rpm it's going to be triggered 200*3000/60 -> 10 thousand times a second.

And be prepared for the overall slowdown in any other code you're running in the arduino because it's going to be being interrupted quite often.

Libraries that depend on software timing loops might misbehave/stop working well when heavily interrupted.
« Last Edit: June 17, 2018, 07:58:38 am by GeorgeOfTheJungle »
The further a society drifts from truth, the more it will hate those who speak it.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2544
  • Country: us
Re: Arduino and interrupts with rotary encoder.
« Reply #4 on: June 17, 2018, 08:20:26 am »
The encoder will be turned by a human.

The Si5351A is a Programmable Any-Frequency CMOS Clock Generator chip.
   https://www.silabs.com/documents/public/data-sheets/Si5351-B.pdf

I would keep the interrupt routine as short as possible.  Only keep track of how many clicks CW or CCW have occurred and save the count.  Then use the resulting count inside your main processing/control loop.  (i.e. read->store copy->clear count and then use stored copy in main loop to control the Si5351A).  That way the main control loop can process encoder changes without missing any encoder input.
 

Offline GeorgeOfTheJungle

  • Super Contributor
  • ***
  • !
  • Posts: 2699
  • Country: tr
Re: Arduino and interrupts with rotary encoder.
« Reply #5 on: June 17, 2018, 08:26:29 am »
Ohh, sorry. Then no matter what any arduino is plenty fast, no problem.
The further a society drifts from truth, the more it will hate those who speak it.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf