Author Topic: Next GH-brewed KB design - 'The Light' (open for discussion)  (Read 109377 times)

0 Members and 1 Guest are viewing this topic.

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #550 on: Thu, 21 June 2012, 08:58:11 »
Hell... let's fill it with Cree XM-L, direct drive, draw 1kW, output 100,000 lumens, melt the keybord, and burn our retinas and fingertips!

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #551 on: Thu, 21 June 2012, 14:47:01 »
My OLIGHT-M21-X has a Cree XM-L with OTF600lm!

22 columns =
("Esc" -> F12 + 2 extra) = 15
(Arrows -> numpad) = 7
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #552 on: Thu, 21 June 2012, 15:00:38 »
Quote from: The_Ed;618815
My OLIGHT-M21-X has a Cree XM-L with OTF600lm!
Heh, not running at maximum!

Quote from: The_Ed;618815
22 columns =
("Esc" -> F12 + 2 extra) = 15
(Arrows -> numpad) = 7
That's not generally how it's done :-)

Offline rknize

  • * Administrator
  • Posts: 1731
  • Location: Chicago
    • metaruss
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #553 on: Thu, 21 June 2012, 15:05:29 »
Since the package is shrouded by the button, it seems like narrow field is what you want.  As for darlington arrays, I've used the ULN2004 types to drive LEDs (and solenoids, motors, etc) in the past.  They are still available in DIP packages.
Russ

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #554 on: Thu, 21 June 2012, 15:08:03 »
It runs at OTF600lm for 5 minutes before going to 60% so that it doesn't melt itself. But I don't need it on for more that 5 minutes to reach the bathroom at any campsite I've ever been in. 20 lumens is the normal level I use it at.

22 columns was what was talked about a few months ago in this thread. It wasn't my contribution either. I'm fine with either 20 or 21 as well.
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline alaricljs

  • I be WOT'ing all day...
  • ** Moderator Emeritus
  • Thread Starter
  • Posts: 3715
  • Location: NE US
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #555 on: Thu, 21 June 2012, 15:14:42 »
The_Ed, that's also not how it's done... mainly you just take the number of switches you want and find a nice even matrix.  For a TKL that could be 9x10.  If you find that you want to neaten up the traces for some reason you can then optimize and add columns if you need them.  One of the things I don't think is necessary would be optimizing for ghosting or NKRO since that can all be handled inside the firmware instead of going crazy on the matrix.
Filco w/ Imsto thick PBT
Ducky 1087XM PCB+Plate, w/ Matias "Quiet Click" spring-swapped w/ XM Greens

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #556 on: Thu, 21 June 2012, 15:22:57 »
Physically laid out 7x22 could be electronically 8x20. Is that what you mean? The traces can connect a physical grid into an electrical grid of different dimensions.
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline bpiphany

  • Posts: 1033
  • Location: Stockholm, Sweden
  • bpiph is a special type of crazy. //mkawa
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #557 on: Thu, 21 June 2012, 15:44:04 »
A more square matrix contains more elements per I/O-pin. Although if you have pins to go around, it may just be more convenient to lay out the matrix in a more rectangular way. In my designs, I've always kept the number of matrix rows equal to the physical rows on the keyboard for simplicity reasons. In this case where a squarer matrix is useful to maximize LED on-time, other optimizations come into play.

Edit: oh, and also, my original idea was to light up one row at a time, and then minimizing the number of rows would be an optimization..
« Last Edit: Thu, 21 June 2012, 15:47:49 by PrinsValium »

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #558 on: Thu, 21 June 2012, 15:55:35 »
We would need extra power to light up a whole row at a time. That's 20+ LEDs drawing current at one time. I thought USB 3 had increased power output. Maybe this will have to be a USB 3 or USB 2 + power brick keyboard.
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline bpiphany

  • Posts: 1033
  • Location: Stockholm, Sweden
  • bpiph is a special type of crazy. //mkawa
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #559 on: Thu, 21 June 2012, 15:59:36 »
Well, that depends on how much current you put through them... There are the 500mA either way it is done. Even with 30mA LEDs eight at a time don't add up to 500, and with only 6 groups instead of say 13 the duty cycle is more than doubled. And 21x30mA is a bit over 500mA but you'd just need to underpower the LEDs a little.

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #560 on: Thu, 21 June 2012, 16:05:08 »
Lighting up more than 8 at a time would mean it couldn't simply use PWM channels from the Teensy++ to do the individual levels any more.

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #561 on: Thu, 21 June 2012, 16:08:03 »
I just looked at pjrc and it said 9 PWM for teensy++. Where did the 8 we've been talking about come from?
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #562 on: Thu, 21 June 2012, 16:15:52 »
Can't remember.
Maybe I stopped counting once I found 8 :-)
More likely because we want to keep one timer free for scanning the columns at a regular rate. That could be arranged differently, but it's a lot of hassle for just one extra PWM.
« Last Edit: Thu, 21 June 2012, 16:18:20 by Soarer »

Offline rknize

  • * Administrator
  • Posts: 1731
  • Location: Chicago
    • metaruss
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #563 on: Thu, 21 June 2012, 16:21:42 »
USB3 leds you draw one additional unit but they also upped the current per unit.  I think it gets you close to an amp.  Still, I don't think we'd want to add such a restriction to the design.  Using PWM is how the other vendors are doing it, no?
Russ

Offline bpiphany

  • Posts: 1033
  • Location: Stockholm, Sweden
  • bpiph is a special type of crazy. //mkawa
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #564 on: Thu, 21 June 2012, 17:36:13 »
I think it might have been me counting the PWM ports on the ATmega32u4 to 8, but that is not the Teensy++, and I may even have done it wrongly... =P

Not using PWM with ~100 LEDs and say 400mA total current would give 4mA per LED. That might be enough, I don't have the experience to tell. Although I have heard that running a LED at say twice it's continuous rating at a 50% duty cycle will in fact make it appear as brighter. But this needs to be verified by someone who actually knows what he is talking about... So there may be other reasons to "PWM" diodes than current limitations.

Also PWM sort of have two slightly different purposes. First to cycle which LEDs are lit to not exceed the maximum current available. I see this as kind of a forced cycling ending up being a degenerate type of PWM. The other reason probably comes closer to the actual meaning of the acronym "Pulse Width Modulation", it is used to actually control the duty cycle and to vary the power output.

In our case the cycling of the groups will constitute an outer power cycle with a fixed duty cycle of 1/8 per group, and within each group there will be a proper (superimposed) PWM at a much higher frequency with a variable duty cycle determining the average power output during that cycle of that group. An image would be great, if I ever get a Boogie Board that could maybe happen... =)

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #565 on: Thu, 21 June 2012, 18:11:23 »
I posted a mock-up before of what a single LED would get. It didn't thumbnail well :-)

Were you thinking of drawing something like this? ...



Effectively that's a 10% 'outer' PWM from the scanning, with a 50% 'inner' PWM from the PWM, so 5% overall.
« Last Edit: Thu, 21 June 2012, 18:15:44 by Soarer »

Offline rknize

  • * Administrator
  • Posts: 1731
  • Location: Chicago
    • metaruss
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #566 on: Thu, 21 June 2012, 19:49:55 »
Yes, I should have said multiplexing + PWM.
Russ

Offline mkawa

  •  No Marketplace Access
  • Posts: 6562
  • (ツ)@@@. crankypants
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #567 on: Thu, 21 June 2012, 23:41:49 »
the question remains: is all this scanning going to need to be done in firmware by the micro? or is there a register it can set every once in a while to control scanning rate and PWM duty cycle? i'm too lazy to read datasheets XD

to all the brilliant friends who have left us, and all the students who climb on their shoulders.

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #568 on: Fri, 22 June 2012, 00:22:09 »
Quote from: mkawa;619192
the question remains: is all this scanning going to need to be done in firmware by the micro? or is there a register it can set every once in a while to control scanning rate and PWM duty cycle? i'm too lazy to read datasheets XD


Do keep up! I outlined this on the 5th!

Scanning is firmware and does the slower part of the PWM. The faster part of the PWM is done by hardware (setting registers).

Of course this might not be how it ends up, but...

Quote from: Soarer;607774
Well I wasn't sure about whether it gave enough control over the PWM to be able to do it in hardware, but actually I think it might.

Timer 2 could be used to run a timebase for the columns at a few kHz.

Timers 1 and 3 can be set to do 8-bit PWM, and have 3 PWM outputs each. Timer 0 is 8-bit anyway, and has 2 PWM outputs.

So each time the column interrupt fires, the handler would do something like...
  • disable PWM outputs
  • disable column n
  • update PWM output compare values
  • enable column n+1
  • enable PWM outputs
  • read keys

Since the column updating forms part of the PWM, any jitter in handling it would result in varying light levels. This would have to be minimised.

The PWM channels should run at some multiple of the column scan frequency. At 16MHz clock and 8 bit resolution they would be running at 62.5kHz. Dividing that by 16 gives roughly 4 kHz, which sounds about right. That would be divided again by the number of columns to get the overall matrix scan frequency, and that wants to be high enough that you don't notice flicker in the LEDs.


(The divide by 16 in that last bit is just so that there are a number of fast PWM cycles in each scan, which helps with minimising the effect of any timing inaccuracies. We can pick whatever divide gives us a nice overall scanning frequency. It would probably be less than 16, to give scanning of a few 100 Hz).

Offline mkawa

  •  No Marketplace Access
  • Posts: 6562
  • (ツ)@@@. crankypants
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #569 on: Fri, 22 June 2012, 00:29:29 »
gerk. i'd rather have a dedicated core for column scanning, so that we don't get any weirdness in scanning the key matrix, but you have a lot more experience with these platforms than i do, so i'll trust you on this one soarer.

to all the brilliant friends who have left us, and all the students who climb on their shoulders.

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #570 on: Fri, 22 June 2012, 03:28:18 »
Eek. That would mean communicating between the two! Actually, key scanning is the easy part - it doesn't have to be done anything like as precisely as we'll be doing it :-)

Offline mkawa

  •  No Marketplace Access
  • Posts: 6562
  • (ツ)@@@. crankypants
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #571 on: Fri, 22 June 2012, 03:42:13 »
the two threads would probably just need to share a register. that's precisely what an interrupt register is tbh, it's a message passing channel between a micro and a bunch of autonomous hardware devices.

to all the brilliant friends who have left us, and all the students who climb on their shoulders.

Offline Djuzuh

  • Posts: 1127
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #572 on: Fri, 22 June 2012, 04:23:57 »
Just to know, how far are we approximately from a prototype, and when will we be able to run the GB?

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #573 on: Fri, 22 June 2012, 04:32:20 »
Damn trolls!

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #574 on: Fri, 22 June 2012, 04:32:33 »
At this point I'd say at least a year 'till we get things into our hands at the end of the GB.
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Djuzuh

  • Posts: 1127
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #575 on: Fri, 22 June 2012, 04:34:04 »
ok :P.

Thanks !

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #576 on: Fri, 22 June 2012, 04:40:31 »
I meant more mkawa with his abstract talk of cores, threads and message passing. But heh!

Offline Djuzuh

  • Posts: 1127
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #577 on: Fri, 22 June 2012, 04:42:04 »
Quote from: Soarer;619333
I meant more mkawa with his abstract talk of cores, threads and message passing. But heh!

OOooooh… :(

I was so happy about your compliment !

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #578 on: Fri, 22 June 2012, 04:50:37 »
Quote from: Djuzuh;619335
OOooooh… :(

I was so happy about your compliment !

'But heh!' implies you too, even if you were less subtle :-p


Those qwerkeys caps look promising! Good timing!

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #579 on: Fri, 22 June 2012, 04:52:33 »
The problem I'm gonna have is how to inject code for the rotary encoders I'll be putting into mine. I can't even begin to code it without the rest of the coding finished and debugged. Or I'd have to write everything from scratch. But the electrical layout will have to be finalized before any coding whatsoever can begin.
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #580 on: Fri, 22 June 2012, 05:04:47 »
Quote from: The_Ed;619337
The problem I'm gonna have is how to inject code for the rotary encoders I'll be putting into mine. I can't even begin to code it without the rest of the coding finished and debugged. Or I'd have to write everything from scratch. But the electrical layout will have to be finalized before any coding whatsoever can begin.

The rest of this doesn't really need any interrupt pins (INT1 .. INT7), so we could make sure to leave you a couple of those - how about port E, that gives you 4, would that be enough? I'd say it's worth you doing some test code just so you know exactly what you would need, in terms of pins and timers etc.

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #581 on: Fri, 22 June 2012, 05:09:16 »
I can code C++ and would be able to use 12 (10 but 12 is easier) variables to make them into "keys" for the regular scanning.
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Djuzuh

  • Posts: 1127
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #582 on: Fri, 22 June 2012, 05:09:51 »
Can I Helps into coding light effects please ? :D

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #583 on: Fri, 22 June 2012, 05:14:24 »
Crap, I'll need more variables... 14 minimum.
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #584 on: Fri, 22 June 2012, 05:19:04 »
Quote from: Soarer;607774
Timer 2 could be used to run a timebase for the columns at a few kHz.

Timers 1 and 3 can be set to do 8-bit PWM, and have 3 PWM outputs each. Timer 0 is 8-bit anyway, and has 2 PWM outputs.


Heh, I just noticed that OC1C and OC0A are on the same pin! Swapping the uses of timers 0 and 2 sorts it out.

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #585 on: Fri, 22 June 2012, 05:19:52 »
It's 5:16AM and you bastards have me coding...

2 rotary encoders

18 variables and a switch case...
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #586 on: Fri, 22 June 2012, 05:24:18 »
Quote from: The_Ed;619342
I can code C++ and would be able to use 12 (10 but 12 is easier) variables to make them into "keys" for the regular scanning.

You're fine for variables, the Teensy++ has loads of memory :-)

We'll be using 32 or so of the I/O pins. For many of them, it doesn't matter which though.

And we'll be using all the timers, if we go with this PWM method. If you want to time the inputs at all, it would have to be using a timebase derived from either a PWM or the scanning timer.

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #587 on: Fri, 22 June 2012, 05:37:19 »
Quote from: Djuzuh;619343
Can I Helps into coding light effects please ? :D

Knock yourself out!

First, how are the display buffers going to work? For output we obviously need one that's the LED matrix. For drawing into we probably want a buffer based on the physical layout - which maybe has extra rows/cols in it, e.g. between number and function rows, that don't get copied to the output.

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #588 on: Fri, 22 June 2012, 05:42:33 »
This probably only makes sense to me. 2 rotary encoders = 20 variables.

It still may cause a slight delay that may be visible in the LEDs. It may have to have a delay so that it processes when it's doing the PWM.

Code: [Select]
X   X X   X
X   X X   X

  X     X

  X     X
  X     X
  X     X
  X     X

  X     X

Edit: No more switch case.
« Last Edit: Fri, 22 June 2012, 06:59:23 by The_Ed »
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Djuzuh

  • Posts: 1127
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #589 on: Fri, 22 June 2012, 06:18:36 »
Quote from: Soarer;619354
Knock yourself out!

First, how are the display buffers going to work? For output we obviously need one that's the LED matrix. For drawing into we probably want a buffer based on the physical layout - which maybe has extra rows/cols in it, e.g. between number and function rows, that don't get copied to the output.

Alas, I have almost no knowledge in µcontrollers or electronics, and can't really follow what you are talking about.

Could you link me to some more information on this project (maybe the existing code), and/or some documentation?

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #590 on: Fri, 22 June 2012, 07:06:32 »
So it will either process at the end of scanning and slightly delay/shorten the PWM cycle, or process during the PWM cycle if that's possible. It would be ideal to process it during the PWM cycle.

Can it process the PWM cycle and rotary encoder code at the same time?
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #591 on: Fri, 22 June 2012, 07:47:20 »
Quote from: Djuzuh;619363
Alas, I have almost no knowledge in µcontrollers or electronics, and can't really follow what you are talking about.

Could you link me to some more information on this project (maybe the existing code), and/or some documentation?

Hmm, there isn't exactly much existing code yet!

By buffer I just mean a 2D array for storing the brightness for each LED, and double-buffered so that you can draw into one while the interrupt is reading from the other.

What I was thinking though, is that the drawing buffer could have more pixels in it than we have LEDs - perhaps a full 7x21 grid. That would make certain effects easier to implement, and more, well, effective :-)

Also, how about having multiple LEDs under the spacebar, to make it more of a grid there? No reason we can't have some LEDs that don't have switches.

These high-level things need thinking of as well as the low-level stuff!

Quote from: The_Ed;619372
So it will either process at the end of scanning and slightly delay/shorten the PWM cycle, or process during the PWM cycle if that's possible. It would be ideal to process it during the PWM cycle.

Can it process the PWM cycle and rotary encoder code at the same time?

Couldn't you process the encoders' signals on interrupts? You could have one for each signal wire. Your interrupt might be delayed a little if the scanning interrupt fires just before you get an input, but it shouldn't be by too much, and wouldn't happen often. The reverse, where your interrupt fires just before the scanning interrupt, could disrupt the LED brightness, but if you code your interrupt to be quick that should be ok too - I reckon you could code it very cleanly that way, since in each interrupt handler you already know which signal has changed.

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #592 on: Fri, 22 June 2012, 08:00:10 »
All my coding experience is with computers, not electronics... I'm used to just plain processing information into output. I've never used PWM, interrupts, and other things of that nature.

Rotary encoders are 2-bit devices. 4 sets of 2-bits is a single input. They need to be polled like the switches. The variables (10 per rotary encoder) process the polled information into the 8-bit codes required for an input.
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #593 on: Fri, 22 June 2012, 08:12:33 »
Just think of the interrupt as doing a lot of the work for you - if you poll you have to figure out whether any signal has changed, but the interrupt tells you that straight off.

With a rotary encoder you don't have to wait for a set of 4 input changes - each single change can be one step, because it's possible to determine which direction it's going in based on the state of the unchanged signal.

Offline mkawa

  •  No Marketplace Access
  • Posts: 6562
  • (ツ)@@@. crankypants
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #594 on: Fri, 22 June 2012, 08:24:51 »
Quote from: Soarer;619328
Damn trolls!
hah! that's the problem with you embedded types; can't see the forest for the trees! :)

anyway if we can get a prototype (bread?) board together, hacking up a basic demo should be pretty quick

to all the brilliant friends who have left us, and all the students who climb on their shoulders.

Offline Djuzuh

  • Posts: 1127
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #595 on: Fri, 22 June 2012, 08:45:36 »
Quote from: Soarer;619378
Hmm, there isn't exactly much existing code yet!

By buffer I just mean a 2D array for storing the brightness for each LED, and double-buffered so that you can draw into one while the interrupt is reading from the other.

What I was thinking though, is that the drawing buffer could have more pixels in it than we have LEDs - perhaps a full 7x21 grid. That would make certain effects easier to implement, and more, well, effective :-)

Also, how about having multiple LEDs under the spacebar, to make it more of a grid there? No reason we can't have some LEDs that don't have switches.

These high-level things need thinking of as well as the low-level stuff!



Couldn't you process the encoders' signals on interrupts? You could have one for each signal wire. Your interrupt might be delayed a little if the scanning interrupt fires just before you get an input, but it shouldn't be by too much, and wouldn't happen often. The reverse, where your interrupt fires just before the scanning interrupt, could disrupt the LED brightness, but if you code your interrupt to be quick that should be ok too - I reckon you could code it very cleanly that way, since in each interrupt handler you already know which signal has changed.


Having a real actual grid to work with while programming would be awesome !

and hm… how will you control the lights? Will there be some sort of FN + something, or will we have dedicated buttons do control the light?

Also, will we be able to change the inserted effects afterwards with the PC?
« Last Edit: Fri, 22 June 2012, 08:47:58 by Djuzuh »

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #596 on: Fri, 22 June 2012, 08:47:53 »
Quote from: Djuzuh;619403
Having a real actual grid to work with while programming would be awesome !

Exactly! Now... I want ripples :-D

Offline Djuzuh

  • Posts: 1127
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #597 on: Fri, 22 June 2012, 08:55:31 »
Meh, ripples can't hold up with a decent typing speed xD.*But it definitively HAS to be on the keyboard imo :]

Offline The_Ed

  • Posts: 1350
  • Location: MN - USA
  • Asperger's... SQUIRREL! I'm Anal Retentive *****!
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #598 on: Fri, 22 June 2012, 09:25:17 »
Quote from: Soarer;619385
Just think of the interrupt as doing a lot of the work for you - if you poll you have to figure out whether any signal has changed, but the interrupt tells you that straight off.

With a rotary encoder you don't have to wait for a set of 4 input changes - each single change can be one step, because it's possible to determine which direction it's going in based on the state of the unchanged signal.


24ppr with only 2-bits would be an insane 96 inputs per rotation and you could only input a multiple of 4. Rotary encoders have physical "bumps" for every ppr. I consider one "bump" as one input. Which means that even though I can tell direction from 2-bits, I still have to use 8-bits for one input.

Remembering about the bumps means I have to rethink the code slightly. I think I know how I'll do it. Positives and negatives from the 2-bits. When 4 is reached in either direction it inputs. But only when it's between "bumps".

I'm down to 16 variables and the inputs will exactly line up with the "bumps".

The polling frequency of 1000hz for the rotary encoders lines up exactly with the polling frequency of the switches. Why would I use an interrupt instead of the polling that's already happening? That seems like a waste of processing.
Reaper "frelled" me... Twice... Did he "frell" you too?... *brohug*
I'm camping for a week, and moving twice in a month. I'll get back to you when I can (If I don't then just send me another PM).
R.I.P.ster

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Next GH-brewed KB design - 'The Light' (open for discussion)
« Reply #599 on: Fri, 22 June 2012, 10:56:14 »
Quote from: The_Ed;619424
24ppr with only 2-bits would be an insane 96 inputs per rotation and you could only input a multiple of 4. Rotary encoders have physical "bumps" for every ppr. I consider one "bump" as one input. Which means that even though I can tell direction from 2-bits, I still have to use 8-bits for one input.

Remembering about the bumps means I have to rethink the code slightly. I think I know how I'll do it. Positives and negatives from the 2-bits. When 4 is reached in either direction it inputs. But only when it's between "bumps".

I'm down to 16 variables and the inputs will exactly line up with the "bumps".

The polling frequency of 1000hz for the rotary encoders lines up exactly with the polling frequency of the switches. Why would I use an interrupt instead of the polling that's already happening? That seems like a waste of processing.

OK, so you have a 'bumpy' encoder, that doesn't change much really :)

Have you got a datasheet for the encoder? I'm wondering how quickly it outputs the sequence...

The interrupts only do processing when necessary - you can't get less wasteful than that! :)

The switch scan rate hasn't been decided yet, btw.
« Last Edit: Fri, 22 June 2012, 10:58:18 by Soarer »