@@aleXelaMec it would be but your still missing the point that encoder counting takes up all your CPU resources so it means you can't do other things at the same time while counting a fast encoder. So if you want to be doing something and counting encoders at the same time then you need to use a hardware encoder counter rather than the CPU to count the encoder
@@outofthebots3122 hey, no, I got your point. At least since my issue is not prolong measurement. I need to count short pulses (around 300ms), but 6 chanels, 2 of each are fast. But thanks for the comment. Ill think about using external Dedicated counter.
Based on the reference schematic in their datasheet, there are two capacitors near the crystal. Did you happen to work out what capacitor values to use?
The capacitors need to match the crystal you use in order to make it resonant for a clocking signal. Instead of using a crystal oscillator I used the timer on the ESP32 to create the clocking signal as ESP32 can create clocking signal up to 40MHz.
@@orhuk quote from datasheet ". Instead of a crystal the fCKi input may also be driven by an external clock.". I just set a timer on the ESP32 to create a high freq PWM with 50% duty and connected it to fCKi
I'm using pigpio to do the counting, and running streaming video over wifi at the same time on a pi ZW. Although things appear to go wrong, it is actually just total cpu overload that is a problem. When I stop the streaming video it all catches up again and the counters are correct (or at least have only a very small error). What software are you using to count?
I did write my own software to do the counting. What I found was the software was close to the external counter chip but it did miss some counts. The Quadrature encoders that use have 11 poles x 4 signals per pole x a 31:1 gear box so this is 1320 signals per rotate so if your rotating at 60RPM this 1320 signals per second. Quite often the motors can be spinning faster than 60RPM and usually I have at least 2 motors on any robot. Most processors with WiFi run the Wifi on a thread with high priority and when the processor is busy with maintaining the WiFi it will miss counts. You will notice this when you compare a software counter with the external counter or if you try to get a robot to drive a perfectly straight line. For my software counter code see my last video, at about 8mins you will see the code and at about 6mins a good explanation of how the code works ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-p4BCFhIuC88.html
Not surprising really that a simple Python loop runs into trouble doing this. I use pigpio to count the pulses, so it's running in a real time process (i.e. high priority) and written in C I believe. I'm also running raspbian lite - so no gui and minimal system services. I found my first runs I had a rogue left over thread still runnig, once I rebooted I found I can stream video over wifi and use pigpio to count the pulses very accurately, There is a slight amount of jitter in the readings when streaming video over wifi, but the overall counts seem to be accurate.
Without a doubt the C code of the pigpio library will be faster than the code from the other link. I started to use the ESP8266 and the ESP32 because they are a real time MCU rather than a micro computer running an OS. In the video above it is running on an ESP32 board so ti is a real time MCU without an OS and all code is compiled to machine code via an C interpreter. No matter how high priority the pigiop library is the OS is still in command and will always have higher priority over resources. At times my robot can have wheels turn as fast as 120RPM and I have a min of 2 wheels driving so this is in the order of 5280 pulses per second and because there is 2 encoders running at the same it it is possible that some of these signals can be at the same time. So signals can be under 0.1ms apart. I started to use a MCU because it is real time so can handle these super small time frames better but still found problems of missing signals and this is why I used the external counter chips and have 1 for each encoder running in parallel. It means signals don't get missed and it also means the over heads r removed from my master processor to allow it to do other stuff.
hey would you be able to share the code that you wrote. I can't seem to understand how the spi.transfer function work. I checked the syntax but can't use it because I don't understand what buffer and val parameters are. would you be able to help on that as well. Thank you
basically I am using Arduino nano to control the motor with an encoder (am-2816a) and an SPI (LS7366R). As the motor rotates the encoder reads the position sends it back to the Arduino through the SPI. I have gone through the research part and know how to do the wiring, but I am stuck with the Arduino program. there is an SPI library in the Arduino software that supports the SPI communication (SPI Pins), and there is a function that I want to use thats called SPI.transfer(). I am having troubles understanding how to use the function and how to receive and send data from and to the encoder. I have used a program that I found online and the output is always -1 even if the motor is at different speeds. I am guessing that there is something wrong with the program. check the links below to know what I have been looking at: arduino.stackexchange.com/questions/16348/how-do-you-use-spi-on-an-arduino Arduino program found online: github.com/werdroid/Arduino_LS7366R Arduino Nano www.farnell.com/datasheets/1682238.pdf encoder www.andymark.com/products/hall-effect-two-channel-encoder SPI lsicsi.com/datasheets/LS7366R.pdf Clock www.ctscorp.com/wp-content/uploads/MXO45.pdf @@outofthebots3122
@@m.a.sherif6878 I don't use Ardunio myself so don't know the SPI library but the first link you posted seemed to me have all the info needed for using SPI. Also I have discovered that STM32 has builtin hardware encoders and there is an Ardunio port for the super common stm32f103c8t6 and it has an ardunio libiary for encoders counters see this thread www.stm32duino.com/viewtopic.php?f=18&t=4024&p=52829&hilit=encoders#p52829
Enocders are hard for pro beginners..your vid here also stated..that many people that wants to try this gets hit by the wall accuracy...so my own test of encoders(gpio input) has also hit a wall. I can read stable 16 counts at 1000 Hertz pr Rpm...which is really not good enough... Now the chip you have is hard to get by(ls7366r) also the code for spi (a sample code) is also hard to get by....as many samples require the right set of parts.... So I think and hope for all on RPI and Arduino as probeginners that you will use a bit of time to make an in depth Tut vid. Every where on RU-vid and on forums you get small bits of the right way.. and for more people the making project it more important to know where you device is currently located then how fast it is going... In sense of robots/3d printers/conyouer belts/... So I wish for xmas, as you seam able to do this....and for all probeginners you will make an in depth project...easy to buy project... Maybe I am hoping for to much. But a man's gotta ask right... Btw thank for your vids. (Sry for my poor English).
Yes good points. The LS7366 is not common found and the user has to write their own custom driver to use it. I have now found another option, the STM32 family of MCUs have hardware encoders on their timers. I am currently using a STM32F103C8t for a robot that I am building am are using the hardware encoders on it. The STM32F103C8t (known as the blue pill) is available everywhere for about $2 and has 4 hardware encoders on it see www.aliexpress.com/wholesale?catId=0&initiative_id=AS_20181217125901&SearchText=stm32f103c8t6. There is an ardunio port for it and there is already libraries for using the hardware timer encoders. If python is your preferred lanuage then there is the pyboard with the more powerful STM32F405RG MCU that runs micro-python see store.micropython.org/
I have purchased the board. So now i Hope you will share some info on thatSTM32F103C8t . Will it handle highspeed as well? ... I have been looking a bit on the industrial encoders. And found that they are affortable for my project- By the way happy new year. I need to finish this project, an i am getting desperate. :-)
@@christiansrensen3810 here is the reference manual for the stm32f103 www.st.com/content/ccc/resource/technical/document/reference_manual/59/b9/ba/7f/11/af/43/d5/CD00171190.pdf/files/CD00171190.pdf/jcr:content/translations/en.CD00171190.pdf you will find from page 329 is the info on the encoder counter. Basically it uses the timer counters to count the encoders. I program it in C but there is ardunio libraries to use the encoder counters as well. I used MX_cube to setup the timers as encoder counters then was just reading the timer_count register to get the current count.
Hi, nice job. How fast can this chip count? Would it be able to handle quadrature pulse at 2Mhz? I'm looking for something that could handle 4 encoders at 2Mhz, any suggestions? Thank you:)
the LS7366R processing speed is set my an external clock signal. Running at 5v it can handle clock signals as fast at 40Mhz. It is recomended that the chip is clocked at 10x the speed of the encoder signals so it should handle signals up to 4Mhz. You will need a Ls7366R for each encoder and they can be chained together on the 1 SPI bus all with separate CS lines see page 14 of the data sheet www.lsicsi.com/pdfs/Data_Sheets/LS7366R.pdf
Hey, I got the chip, its on a board, but should work the same: www.mikroe.com/counter-click Trying to make it work with 1 encoder. I got MISO,MOSI,SCK,CS connected to Raspberry PI3, and im using the bcm2835 driver for SPI. www.airspayce.com/mikem/bcm2835/group__spi.html Im using the datasheet for correct commands/registers, however the bytes read from chip are always all zeroes. Any help apreciated:)
That little board is basically what I built the on a bread board as it was cheaper for me to do that. You will also need to set the enable pin to high before it will count and of course connect your power and gnd. There is a couple of register to write to for setup before reading the counter too.
a question...i use this device on an arduino...does reading CNTR register influences the counting?Because on the data sheet productor writes (i understand this manner) to read back from OTR register...what is the right way ...?thank you