alternatief voor rotary encoder in chip vorm?

Euhm wat wil je doen? Een bestaande encoder vervangen door 2 drukknoppen of iets nieuw maken? Een standaard rotary encoder stuurt gray uit als volgt 00 01 11 10. Die sequentie bepaalt de richting... lees je eerst 00 en dan 01 in dan draai je bv naar rechts, lees je eerst 00 in en daarna 10 draai je naar links. Die sequentie kan éénder waar beginnen en kan snel of trager gaan. Zit meestal ook ruis/dender op enzo ... niet altijd gemakkelijk om het goed te krijgen. Je moet dus gewoon gray code aanbieden in een bestaand ontwerp in een bepaalde sequentie en snelheid.
 
Hey Toon,

heb er idd geen kaas van gegeten :).
Maar idd ik wil een bestaande encoder en 3 switches vervangen met 2 druk knoppen.
Deze bepalen het geheugen adress waar een sample word opgeslagen (casio SK1)

Dus is de manier een pic proggen die gray code uitstuurd waar dan die twee druk toetsen aan zitten?

Cheers

Tim
 
Ik programmeer mijn encoders als volgt:
Een van de schakelaars noem ik de clock (A) de andere data (B)
Dan laat ik een interrupt service routine starten op de neergaande flank van de clock.
In die service routine kijk ik of de data hoog danwel laag is.
De neergaande flank van de clock verteld me dat er aan de encoder gedraaid is en het hoog resp. laag zijn van de data verteld me links of rechts om.
7DF4A388-7CB2-4F12-ACC9-8AA8742B2A6F.jpeg
 
grappig, ik heb altijd het omgekeerde willen doen, synths waar enkel +/- op zit modden met extra encoder

is het voor het modden van een bestaand toestel?
 
@Grumble @krautrock1958 Hier kom ik op uit met chatGPT.
Ok het wil me eerst veel te dure spullen aansmeren maar uiteindelijk heb ik als suggestie een
PIC10F

Me:
Hi, how can I replace an encoder with 2 push buttons?


To replace an encoder with 2 push buttons, you can use digital inputs on a microcontroller or single-board computer to read the state of the buttons, and then use software to interpret the button presses as encoder rotation. The specific steps would depend on the microcontroller or board you are using and the programming language you are using. But in general, you would need to:
  1. Connect the push buttons to digital inputs on the microcontroller or board
  2. Write code to read the state of the digital inputs
  3. Use an algorithm to interpret the button presses as encoder rotation
  4. Write code to perform the appropriate action based on the interpreted rotation.
It's important to keep in mind that the accuracy and responsiveness of this solution may not be as good as a real encoder, but it can be a good solution for some applications where the cost or complexity of an encoder is not feasible.

me:
which microcontroller would you recommend that is cheap and just enough for this task?


There are many microcontrollers that are suitable for this task and can be considered cheap. Some popular options include:
  • Arduino: The Arduino platform is a popular choice for hobbyists and beginners, and there are many different boards available that are based on the AVR microcontroller. The Arduino Uno and Arduino Nano are two popular boards that are relatively inexpensive and have a large community of users.
  • ESP8266/ESP32: The ESP8266 and ESP32 are low-cost WiFi-enabled microcontrollers that can be programmed using the Arduino IDE. They have built-in WiFi, which allows you to connect the microcontroller to a network and control it remotely. The ESP32 has more memory and processing power than the ESP8266.
  • STM32: The STM32 line of microcontrollers from STMicroelectronics is a bit more powerful than the Arduino, and is suitable for more advanced projects. They come with a variety of peripheral options such as USB, CAN, Ethernet and more, at a cheap cost.
  • PIC: Microchip PIC microcontrollers are inexpensive, powerful and easy to program. They have a wide range of products suitable for different needs, from simple applications to advanced ones.
Ultimately, the best microcontroller for your project will depend on your specific requirements and the resources you have available. You should take into account factors such as cost, processing power, memory size, and the availability of development tools and libraries when choosing a microcontroller.

me:
That does not make sense these are way too expensive. can you suggest something form microchip?


I apologize for the confusion, you are correct that the microcontrollers I listed previously may be considered expensive for some applications.
Microchip Technology Inc. has a wide range of microcontrollers that are suitable for different needs and are relatively inexpensive. Some examples of Microchip microcontrollers that can be used for your application are:
  • PIC10F: Microchip PIC10F microcontroller are very cheap and small in size, they have few I/O pins and low memory, but they can be a good solution for simple applications that do not require a lot of processing power or memory.
  • PIC12F: Microchip PIC12F microcontroller are also very cheap and small in size, they have more I/O pins and memory than PIC10F, They can be a good solution for simple applications that require more I/O pins and memory than PIC10F.
  • PIC16F: Microchip PIC16F microcontroller are also very cheap, they have more I/O pins, memory and processing power than PIC10F and PIC12F, They can be a good solution for applications that require more memory, processing power and I/O pins than PIC10F and PIC12F.
It's important to note that these microcontrollers may not have as many features as the other microcontroller I mentioned earlier, such as built-in WiFi or USB, but they are suitable for simple and cheap applications.
Please let me know if there is anything else I can help you with.

Me:
The PIC10F looks good. can you write an embeded c program that generates grey code like an encoder, to scan the 2 inputs and runs an interrupt routine on the falling edge of the clock? It should detected which button is pressed and generate gray code on the output. 1 button represents left rotation the other a right rotation.


Sure, here is an example of an embedded C program that generates gray code like an encoder, scans the 2 inputs, and runs an interrupt routine on the falling edge of the clock. It should detect which button is pressed and generate gray code on the output. The left button represents left rotation, and the right button represents right rotation.
#include <xc.h>

// Configuration bits
#pragma config FOSC = INTOSCIO // Internal oscillator
#pragma config WDTE = OFF // Watchdog timer off

// Global variables
unsigned char button1 = 1; // Left button
unsigned char button2 = 1; // Right button
unsigned char grayCode = 0; // Gray code output
unsigned char direction = 0; // Rotary direction (0 = left, 1 = right)

// Interrupt service routine
void interrupt ISR(void) {
if (INTF && INTE) { // Check for falling edge of clock
INTF = 0; // Clear interrupt flag
button1 = PORTBbits.RB0; // Read left button
button2 = PORTBbits.RB1; // Read right button
if (button1 == 0 && button2 == 1) { // Left button pressed
direction = 0; // Set rotary direction to left
grayCode++; // Increment gray code
if (grayCode > 3) { // Check for overflow
grayCode = 0;
}
} else if (button2 == 0 && button1 == 1) { // Right button pressed
direction = 1; // Set rotary direction to right
grayCode--; // Decrement gray code
if (grayCode < 0) { // Check for underflow
grayCode = 3;
}
}
}
}

// Main function
void main(void) {
OSCCON = 0b01110000; // Set internal oscillator to 8 MHz
ANSEL = 0; // Set all pins to digital
TRISB = 0b00000011; // Set RB0 and RB1 as inputs
INTE = 1; // Enable external interrupt on RB0
INTF = 0; // Clear interrupt flag
GIE = 1; // Enable global interrupts
while (1) {
PORTB = grayCode; // Output gray code to PORTB
}
}

This program uses the PIC10F microcontroller, and it runs on internal oscillator of 8MHz, so you need to set the configuration bits accordingly. It uses two input pins (RB0, RB1) to read the state of the two push buttons, and the external interrupt feature on RB0 to detect a falling edge of the clock signal. The program uses two global variables, button1 and button2, to store the state of the buttons. When the interrupt service routine (ISR) is triggered, it reads the state of the buttons and checks which button is pressed. If the left button is pressed, it increments the gray code and sets the direction to left. If the right button is pressed, it decrements the gray code and sets the direction to right. The gray code is then output to PORTB.

Please keep in mind that this is just an example and you may need to adjust it depending on your specific hardware setup and requirements.
 
ooh ja shit had chatgpt moeten zeggen dat het een 4bit grey code betreft.

No problem, I understand your requirement now. Here's an updated version of the code that generates 4-bit gray code and scans the 2 inputs, and runs an interrupt routine on the falling edge of the clock. It detects which button is pressed and generates the 4-bit gray code on the output. The left button represents left rotation, and the right button represents right rotation.
#include <xc.h>

// Configuration bits
#pragma config FOSC = INTOSCIO // Internal oscillator
#pragma config WDTE = OFF // Watchdog timer off

// Global variables
unsigned char button1 = 1; // Left button
unsigned char button2 = 1; // Right button
unsigned char grayCode = 0; // Gray code output
unsigned char direction = 0; // Rotary direction (0 = left, 1 = right)

// Interrupt service routine
void interrupt ISR(void) {
if (INTF && INTE) { // Check for falling edge of clock
INTF = 0; // Clear interrupt flag
button1 = PORTBbits.RB0; // Read left button
button2 = PORTBbits.RB1; // Read right button
if (button1 == 0 && button2 == 1) { // Left button pressed
direction = 0; // Set rotary direction to left
grayCode++; // Increment gray code
if (grayCode > 15) { // Check for overflow
grayCode = 0;
}
} else if (button2 == 0 && button1 == 1) { // Right button pressed
direction = 1; // Set rotary direction to right
grayCode--; // Decrement gray code
if (grayCode < 0) { // Check for underflow
grayCode = 15;
}
}
 
Laatst gewijzigd:
Back
Top