Dave, on the video you told us that putting the rotary encoders on the I2C I/O would not be a good idea. But speed isn't really an issue with encoders is it? Could you explain?
You might want to consider putting a faster chip in the board, like the ATMEGA328
Running out of processing speed? You might want to consider putting a faster chip in the board, like the ATMEGA328 that can run easily 2 times faster at 16MHz.
And you can even clock it at 20Mhz!
I don't think that is quite necessary. The main rason for any slowness are the bloated Arduino libraries. Just replacing crap Arduino calls like digitalWrite and digitalRead with direct port reads and writes will make a huge difference already.
nickgammon, personnaly i do not understand how your rotary encoder method would work, would it not involve atleast 2 pulses to tell direction, in place of 1 for daves method,
Forward direction: LH then HH, or HL then LL
Reverse direction: HL then HH, or LH then LL
// Interrupt Service Routine for a change to encoder pin A
void isr ()
{
if (digitalRead (PINA))
up = digitalRead (PINB);
else
up = !digitalRead (PINB);
fired = true;
} // end of isr
They are not crap, they do what they are designed to do, which is to simplify programming. Direct port reads and writes will be faster, particularly if you know in advance what port you want to access.
void digitalWrite(uint8_t pin, uint8_t val)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
if (port == NOT_A_PIN) return;
// If the pin that support PWM output, we need to turn it off
// before doing a digital write.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
out = portOutputRegister(port);
uint8_t oldSREG = SREG;
cli();
if (val == LOW) {
*out &= ~bit;
} else {
*out |= bit;
}
SREG = oldSREG;
}
PORTB |= _BV(SOME_PIN);
(which incidentally usualy gets optimised to a single instruction)But if you want to set (say) 10 consecutive pins to output then it becomes trickier.
In any case, reading rotary encoders is best done by an interrupt service routine, in which case the question of whether or not digitalRead is slow becomes a bit academic.
Not really. Bloated and slow code is bad, whether in an ISR or not
PORTB |= _BV(SOME_PIN);
digitalWrite (10, HIGH);
digitalWrite (10, HIGH);
Bloated and slow code is bad ...
After watching Dave spending - how long? - debugging the SPI problems ... was it really worth it to save a few bytes, when he will have 12 Kb over anyway?
I have deleted that posting because of the Arduino wankers who anyhow won't get it.
But Dave did use the oh so great Arduino calls, so your argument doesn't cut it.
I have previously posted in some of the power supply threads how to do encoder reading the right way. I have deleted that posting because of the Arduino wankers who anyhow won't get it.
I have deleted that posting because of the Arduino wankers who anyhow won't get it.
Not really. Bloated and slow code is bad, whether in an ISR or not
That's your opinion, right?
There's a school of though that unreadable code is bad.
Compare:Code: [Select]PORTB |= _BV(SOME_PIN);
to:Code: [Select]digitalWrite (10, HIGH);
In your case you have to make sure that you have PORTB right, and SOME_PIN right. Back to the datasheet, to see if pin 10 is on PORTA, PORTB or PORTC. And work out which bit SOME_PIN is.
And if I read your code I have to check you got it right.
But if I read:Code: [Select]digitalWrite (10, HIGH);
... I know someone is setting pin 10 on. No argument.
Does it matter if I am turning on a light in fish tank? Do the fish notice if the light comes on a few microseconds later? Come on.
... except perhaps Arduino fanboys.... and then to be happy finishing it off with sloppy code
Dave, what are the dimensions of the board?
If insulting people is how this forum works, I will happily leave it right now.
My first processor had 256 bytes of memory, so I know something about writing tight code. But you don't really care about that do you?
If you really, truly, believe that you can prove how smart you are by calling people "wankers" and "fanboys" well, welcome to a small, closed world of people who don't mind being insulted.
Please ignore the idiots. I for one like your contributions. The idiotic posters around here are the reason so many forums have an iron fist moderation policy. Dave is more liberal than that, but it does mean we have to put up with a certain background noise level.