Reading a rotary encoder
Reading a rotary encoder
Hi
Can i just check… there are no commands in Annex that allow easy reading of a rotary encoder, right? I searched and I see nothing… but I am often blind! One has to write it from scratch. If anyone can confirm back it would be great. I dont want to write a sub from scratch only to discover that I missed an easy way to do it! There are so many amazing Commands in Annex that one starts to expect it to do everything!
Best wishes to all..
Can i just check… there are no commands in Annex that allow easy reading of a rotary encoder, right? I searched and I see nothing… but I am often blind! One has to write it from scratch. If anyone can confirm back it would be great. I dont want to write a sub from scratch only to discover that I missed an easy way to do it! There are so many amazing Commands in Annex that one starts to expect it to do everything!
Best wishes to all..
- PeterN
- Posts: 392
- Joined: Mon Feb 08, 2021 7:56 pm
- Location: Krefeld, Germany
- Has thanked: 184 times
- Been thanked: 220 times
- Contact:
Re: Reading a rotary encoder
Our friend Fernando seems to have some experience on this topic:
[Local Link Removed for Guests]
Good luck!
[Local Link Removed for Guests]
Good luck!
- cicciocb
- Site Admin
- Posts: 2060
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 439 times
- Been thanked: 1358 times
- Contact:
Re: Reading a rotary encoder
If I remember well there is a "not documented" feature that supports the optical encoders using the chip H/W counters.[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Mon Oct 02, 2023 2:51 pm Hi
Can i just check… there are no commands in Annex that allow easy reading of a rotary encoder, right? I searched and I see nothing… but I am often blind! One has to write it from scratch. If anyone can confirm back it would be great. I dont want to write a sub from scratch only to discover that I missed an easy way to do it! There are so many amazing Commands in Annex that one starts to expect it to do everything!
Best wishes to all..
I just need to look inside the code .....
- cicciocb
- Site Admin
- Posts: 2060
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 439 times
- Been thanked: 1358 times
- Contact:
Re: Reading a rotary encoder
Yes, I confirm that there is a "forgotten" feature that use the internal PCNT counters to read the encoders. (ESP32)
The functions are the following :
ret = ENCODER.SETUP pin1, pin2 [,mode]
where mode can be 0-> single, 1->half, 2->full
set the pins and the mode; returns always 0
ret = ENCODER.COUNT
returns the number of impulses counted
ret = ENCODER.RESET
reset the counter and returns 0
ret = ENCODER.SETVALUE value
set the the counter at a given value, return always 0
this is a very simple example using the pins 18 and 19
The functions are the following :
ret = ENCODER.SETUP pin1, pin2 [,mode]
where mode can be 0-> single, 1->half, 2->full
set the pins and the mode; returns always 0
ret = ENCODER.COUNT
returns the number of impulses counted
ret = ENCODER.RESET
reset the counter and returns 0
ret = ENCODER.SETVALUE value
set the the counter at a given value, return always 0
this is a very simple example using the pins 18 and 19
Code: [Local Link Removed for Guests]
wlog encoder.setup 19,18
timer0 1000, count
wait
count:
wlog encoder.count
return
Re: Reading a rotary encoder
Fabulous. One really does start to believe that Annex32 can do everything!
Thank you!
Thank you!
- Fernando Perez
- Posts: 378
- Joined: Mon Feb 15, 2021 10:09 pm
- Location: Santander (Spain)
- Has thanked: 195 times
- Been thanked: 267 times
Re: Reading a rotary encoder
Pedro, thanks for remembering, but it seems that both Eloclegin and Cicciocb are referring to rotary optical encoders, which are used to control the speed and, eventually, the position of a motor that rotates in a single direction.
My experiments were with mechanical encoders. Which has much more merit because the difficult thing is determining the direction of rotation and acting accordingly.
My experiments were with mechanical encoders. Which has much more merit because the difficult thing is determining the direction of rotation and acting accordingly.
- cicciocb
- Site Admin
- Posts: 2060
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 439 times
- Been thanked: 1358 times
- Contact:
Re: Reading a rotary encoder
No, the function decodes also the direction and can be used with mechanical encoders. The advantage is that it can increase the resolution of the pulses detecting edges (using the mode option)
- Fernando Perez
- Posts: 378
- Joined: Mon Feb 15, 2021 10:09 pm
- Location: Santander (Spain)
- Has thanked: 195 times
- Been thanked: 267 times
Re: Reading a rotary encoder
It would be spectacular. Can you give us some example?
Edit: It seems to work. I have connected a KY-040 to pins 18 and 19 and the counter increments and decrements depending on the direction of rotation.
Do you have more things hidden inside Annex?
Edit: It seems to work. I have connected a KY-040 to pins 18 and 19 and the counter increments and decrements depending on the direction of rotation.
Do you have more things hidden inside Annex?
- cicciocb
- Site Admin
- Posts: 2060
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 439 times
- Been thanked: 1358 times
- Contact:
Re: Reading a rotary encoder
Yes, there are some more[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Mon Oct 02, 2023 7:04 pm It would be spectacular. Can you give us some example?
Edit: It seems to work. I have connected a KY-040 to pins 18 and 19 and the counter increments and decrements depending on the direction of rotation.
Do you have more things hidden inside Annex?
Re: Reading a rotary encoder
Searching for something else this topic surprised me. An undocumented, even hidden feature!
My favourite Annex as an adventure...
Had ever written a routine for this function but tried this and it works fine. easy piece now.
Don't forget the capacitors on the ports when using a cheap mechanical encoder.
Any other surprises?
My favourite Annex as an adventure...
Had ever written a routine for this function but tried this and it works fine. easy piece now.
Don't forget the capacitors on the ports when using a cheap mechanical encoder.
Any other surprises?
From profession to hobby. Micro-computers still my challenge!