![]() |
Forum Index : Microcontroller and PC projects : Quadrature Encoder reading...How cool is this..
Author | Message | ||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Just hooked-up 3 quadrature encoders to my Parallax P2. I intend for the P2 to do all the heavy-lifting for future machine control and the Picomite will be dishing-out commands....one heck of a combo ![]() The P2 has "smartpins" and all 64pins are identical. Here, we nominate a pin to be a quadrature decoder/counter. Of course, this requires 2 pins and so it uses an adjacent pin. Point being is that; the pin 'A' delivers a signed, 32bit count with ZERO impact on any of the 8 CPUs!!! ![]() ![]() ![]() '' simple quad-encoder in BASIC '' const _clkfreq = 160_000_000 const enc_z = 32 ' encoder A pin, B pin must be 1 higher const enc_y = 30 ' encoder A pin, B pin must be 1 higher const enc_x = 28 ' encoder A pin, B pin must be 1 higher dim encval as long pinstart(enc_x, P_PLUS1_B + P_QUADRATURE + P_SCHMITT_A + P_HIGH_15K + P_OE, 0, 0) 'init encoder with pullups pinhigh(enc_x) 'high for pullup wrpin(enc_x+1, P_SCHMITT_A + P_HIGH_15K) 'B pin: only schmitt + pullup pinhigh(enc_x+1) direction(enc_x) = input ' reset count to zero by toggling DIR bit direction(enc_x) = output pinstart(enc_y, P_PLUS1_B + P_QUADRATURE + P_SCHMITT_A + P_HIGH_15K + P_OE, 0, 0) 'init encoder with pullups pinhigh(enc_y) 'high for pullup wrpin(enc_y+1, P_SCHMITT_A + P_HIGH_15K) 'B pin: only schmitt + pullup pinhigh(enc_y+1) direction(enc_y) = input ' reset count to zero by toggling DIR bit direction(enc_y) = output pinstart(enc_z, P_PLUS1_B + P_QUADRATURE + P_SCHMITT_A + P_HIGH_15K + P_OE, 0, 0) 'init encoder with pullups pinhigh(enc_z) 'high for pullup wrpin(enc_z+1, P_SCHMITT_A + P_HIGH_15K) 'B pin: only schmitt + pullup pinhigh(enc_z+1) direction(enc_z) = input ' reset count to zero by toggling DIR bit direction(enc_z) = output do encval = rdpin(enc_x) ' read encoder print "X-axis encoder: ";encval encval = rdpin(enc_y) ' read encoder print "Y-axis encoder: ";encval encval = rdpin(enc_z) ' read encoder print "Z-axis encoder: ";encval pausems 500 ' wait 1/2 second loop |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
Of course, you could probably put an encoder on each of the 8 Pico state machines and use the spare CPU core to DMA the values to RAM. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
8? Meh, chicken-feed. Allowing for a Tx and Rx, the P2 can handle 31 encoders at up to sys_clock (300 MHz+) with all 8 "cogs" (CPUs) standing idle ![]() Of course there is no such encoder; most industrial products are good for 500KHz. I have a bunch running at 1.6MHz+ but that is not very common. ![]() |
||||
scruss Regular Member ![]() Joined: 20/09/2021 Location: CanadaPosts: 91 |
Since a bare P2 costs the same as qty 4 Raspberry Pi Picos, you could manage quite a few encoders ... |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Once I have the axis-position data, I then need to process 6 PID loops in 65uS, 6 velocity profilers in 128uS and then I need sample-accurate synchronised motion between any combination of axes. Oh and the motor command resolution (PWM) is 16bit at a minimum 20KHz. No amount of strung-together Picos will ever cope with these specifications. |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Does the encoder reader do any signal filtering? For contrast, various PIC chips with QEI modules have setable encoder input signal filters. Performs in effect debouncing at a hardware level. Visit Vegipete's *Mite Library for cool programs. |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Funny that you should ask; during the development phase of the P2, filtering was my contribution ![]() Another of the many counter modes is the ability count pulse & direction. There are some really capable, low-cost CNC controls from China but they only output pulse & direction (up to 500KHz). How can these be retrofitted to existing machine-tools that already have industry-standard +/-10v analogue commanded servo drives? The P2 can take the pulse & direction and apply it as a position command to the closed-loop PID ![]() ![]() Edited 2021-11-12 16:51 by Tinine |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5089 |
That is a very cool chip. No wonder you promote it. Perfect for this application. And yes, you can buy many picos for that price, but the few dollars can not offset the gain in development. Just perfect for the task. PicomiteVGA PETSCII ROBOTS |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Well I'm like a giddy schoolgirl with this thing...There really are no (practical) limits :) I only promote it here because I like to keep my secret weapons...well, secret :) But anyone with MM-performance-anxiety can easily off-load the time-critical stuff to either the P1 or P2 and retain the benefits of the MM. Thankfully, Parallax don't care about the mainstream...their products make me appear to be the wizard that I'm not. I have gone with the relatively expensive P2 Edge module. This is a 6-layer board and I am currently running below the recommended speed of 180MHz (160MHz). Others are running at 300MHz+. Using a "slow" memory model, I am executing BASIC code @5M "lines/second"....Per processor and there are 8 processors!!! The 64 "smart pins" are like processors in their own right...zero CPU impact. You have a loop running but a particular function is slowing the loop down? Just specify "CPU" as part of the function call and the Prop finds another free CPU to run that function. One could write a huge file to SD and the main loop wouldn't skip a beat. Fun, fun, fun :) |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |