torstai 24. lokakuuta 2019

ARB waveform generation


I've had GWInstek AFG-2005 pulse generator for a while, but so far I haven't needed to arbitrary function generator part of it. Now, however, I ran onto a case where it would be useful so I downloaded the PC software to see how difficult it would be to generate sequence I need.

Knowing that many of these manufacturers' software is, shall we say, of dubious quality, I kinda expected at least some amount of frustration, although GW's reputation isn't even close to worst.


First troublesome thing is that it uses memory points as horizontal axis, instead of time. I don't care about points! Give me time axis! Going through menus quickly, there is "period or number" selection but that doesn't seem to change anything. Figures. (pun intended)
 
On vertical axis; generator has 10-bit (so 1024-level) output, so values go from -511 to 511. -512 is not apparently there (so 1023 levels, not 1024), which doesn't bother me too much actually. Again, I'd prefer voltage, but meh, this works for me, at least for now.

(later note: actual output level can be set via generator itself, and -511..511 matches set full peak-to-peak range.)

I wanted to start with simple square wave, and there is handy dialog for this.


There was output rate selection when opening the software, and I think I selected 100 samples/s there. I wanted 10 pulses over 1 second, and it took me a while to figure this out. Points, period and freq here indicate same thing; total length of generated sequence. Below those, 'cycle' indicates how many cycles of signal to create. A bit confusing but okay-ish...

So after this I got the first screen. My signal is kinda tiny there, on right hand corner, right? Okay, let's zoom in and ... What?!?

Why is this zooming also vertical axis (so with some zooming vertical is reduced to 500), I wanted to keep my whole signal range on view? And why is there that brief period of inactivity in start? And why is there some 12 cycles instead of 10? What?

(later note: after some more fiddling around, it seems that this generate button is "apply more data to end" and not "generate signal", so I guess there was something already from what I did before getting here.)

But okay, let's try this. Send to instument.. I don't feel like taking another picture anymore, but why is this suggesting some random range by default (start 0, length 20), instead of the entire signal I just generated here? Sending worked well enough with USB and generator switched to it automatically. And yes, generated output is same as here, with that unwanted blank period in there as well. Although I had to set frequency on the generator itself to 1 to return this signal to the length I actually wanted.

The waveform is saved with CSV extension, but unfortunately it isn't CSV as in Comma Separated Values file generated by for example Excel. It is text file nevertheless so if (I think that's "when") needed I can generate it manually. Why is there that comma between "Start:" and value though?

Start:,0,
Length:,100,
Sample Rate:,20000000,
511,
511,
511,
511,
511,
...


...All in all, this thing is not great, but I can work with this.

Edit a bit later: After turning the signal generator power off and back on the next day, I was pleasantly surprised that it had previous mode set; ARB with frequency I set. After some puzzled testing I was somewhat less pleased to find out that this was effectively a lie; it was not outputting the waveform I used last time but some basic square wave instead. Not nice.






sunnuntai 20. lokakuuta 2019

Keyboard layout issues

Bit of mild rant, bit of memory lane...

Back in the 90s, when I first got into flight simulators, I learned the hard way that I had to switch the computer to US keyboard layout to even play the games. This was because Finnish keyboard layout has keys 1-0 and + and ´ on top row (excluding whatever is the leftmost key, and backspace), while games expected US layout where keys there are 1-0, - and =. On Microprose simulators and many others these keys were typically used for throttle controls, so without them even take off was impossible. Between different keyboard layouts only A-Z and 1-0 are common between layouts (completely ignoring non-latin alphabets, and even within latin charset there are exceptions like AZERTY layout), and pretty much all other characters move around when switching between them.

I recently bought Stardew Valley and found it surprisingly fun game. It did, however, bring me back few decades due to this very same keyboard issue I though long since solved.

Why this came into my mind is that Stardew Valley has keyboard shortcuts, 12 of them to be exact, for quick access to items. Short cut keys being 1-0, - and =, to be specific. So, the abovementioned US layout. And of course it doesn't work properly with Finnish layout, not with the actual keys, nor by using, say, - character (which happens to be in bottom row in this layout). So I can't use two rightmost items with keyboard. And here I thought we had left these issues behind some 20 years ago.

Funnily enough, it shouldn't be that difficult to make game keyboard universal. Almost all keyboards have operated, and as far as I know, still operate only on "scan codes" that indicate physical position of a key on keyboard that was pressed or released, and translation to actual characters doesn't happen until your operating system gets involved. Keyboards are all standard these days regarding normal keys, and only vendor-specific keys do require specific driver to translate them to useful function.

Last time I actually dealt with the scan codes was some 20 years ago so my memory may be a bit hazy here, but I seem to recall that it mostly went top to bottom and left to right; ESC being 1, F1 2, then proceeding to I think F10 (F11 and F12 being added later to sequence and therefore had different codes) before proceeding to next row; the leftmost key, 1 onward until backspace, then tab... And keypad portion later on sequence.

Operating system (or more specifically, keyboard driver) typically takes care of translating these codes to actual characters so often you don't have to even know about them on application level. Only when building things like Stardew Valley's 12-item shortcut bar you'd want to take different route to avoid the layout issues like this.

Most, if not all common APIs do report keyboard scan codes as well on key press, so all game would have to do here is to track them instead of characters to make your game work regardless of user's keyboard layout.

The other part, showing user the key "name", I haven't ever used, but I am certain that somewhere there is a application-level function to translate scan code to key name too, just for this purpose. And voilá, no more keyboard layout issues!

Now I just have to wonder, if user isn't using QWERTY layout (but something else like AZERTY), do character movement break too, since game uses ASDW for directional movement? I'd hope not.



tiistai 15. lokakuuta 2019

ATV electric conversion part 2: The parts


Previous part here .

I avoid mentioning any brand names here, for no special reason, I just don't want to. It is not hard to find similar (or exactly the same) parts for yourself.

Looking for components was kinda annoying. I started from US-centric site and found many great looking alternatives, but almost without exception they were not shipping to Europe. Fortunately Ich kann wenig Deutch sprechen so I could go to German site and for parts there. The selection appears to be much smaller for some reason, so some compromises needed to be made.

It took a few tries (first on US side, then German) to refine my searches to suitable keywords so started getting what I wanted. For motor and controller I searched for "24v motor kit" in few variations, eventually ending up with 350W set that included controller, throttle, motor, chain and few other parts (for total of about 100€).

Next was battery. While a lead-acid battery (or two) could be obtained for less, this kind of use requires deep discharge batteries that tend to be more expensive, so I went for lithium-ion battery.
I quickly found suitable-looking 24v 20Ah unit (for about 200€), so no problem there.

A quick mention of prices: At no point I expected this to be, shall we say, frugal project, as already built electric ATVs can be found on market for less. For me, this is learning project first and foremost, and getting dead ATV running (instead of calling it a total loss) for enjoyment of kids will be nice incentive to get this done.

Before going any further I of course wanted to test that things work properly. Battery had wrong kind of connectors (as I pretty much expected), but changing it was very simple operation as motor kit came with correct connector blank. Just be very very careful not to short those battery wires during this operation...


Connect everything (well, main parts), turn key and it came alive. Twist of throttle starts motor, and although everything works nicely, I also immediately see that my previous fears of a serious build problem are confirmed and I have to figure out solution to that before build can proceed much further.
 
Next up, taking apart the ATV itself.



perjantai 4. lokakuuta 2019

DF-DFERH-01


Rant time, and as usual, some strong language is involved. 

Kid wanted to make some purchases in Google Play. Specifically in-app purchases for a game. While I am not too happy about this, I could begrudgingly allow it - as long as it isn't too often, and not too expensive stuff (although it's kinda relative, I guess.)

So I went and bought a small Google Play gift card. This is after all what they are for, right? To allow someone to make purchases without having to have something like credit cards.

When I went to activate this card on his account, I only got this completely useless error, "DF-DFERH-01" and something about not being able to load data (exact phrasing escapes me; no matter what I gave as code, even "123" gave same error) Googling that message is completely useless too, all I got was same "reset app data" advice (from several years ago, so not exactly current info), just in way more words than necessary. As you can guess, all that was completely useless.

Now, kds account is under Google Family Link control, and I started to suspect this is related. And sure, after some digging through various pages it seems that kids under 13 cannot use these gift cards. What The F***? Why?!? And if so, why doesn't the system give actually useful error about that, instead of that useless error? Guess that's google for you, half-assing everything that isn't used by 90+% of their advertising targets (I'm seriously temped of using certain other words here, but I'll hold my proverbial tongue her.e

Okay, there was this mention of family account. Of course that doesn't work at all in my computer's web browser at all (another half-assed thing) so I had to use that via android app (which I hate since it's sloooooow). Except now it only allowed me to use credit card as payment option for this shared account (despite my personal account still having some 10+ euros on it since I got myself a gift card before; nevermind this gift card I'm still holding.)

So, Google, let me get this straight: I am supposed to use my personal credit card that I am by bank's rules not supposed to give to anyone  to allow  anyone in my family, including kids to make purchases with? Think carefully about that before responding. Last I checked this is 100% against any credit card agreement, even us US - and this is EU where even more stringent regulations just came in effect.

To make this worse, I can't even use this gift card I paid actual money for to top up this family account funds so those could be used first. It only accepts credit cards. Again, What The Actual F***, Google?

At the moment, I am almost pissed off enough to contact few certain financial agencies (note plural, not limited to local ones) to make some queries about exactly how dubious this kind of arrangement actually is...


keskiviikko 2. lokakuuta 2019

Windows 10 and mandatory Microsoft account


On trade fairs, I've used a monitor and my laptop for presentations. Usually I have somewhat related slideshow running, and when I need to present something I bring out other windows like browser.

Laptop there is not great. It has relatively small screen and takes up some space on the table, so when a new fair-like event was coming up now, I checked if I could find something better, remembering that I had somewhere seen small PCs that attach directly to back of display.

Instead of those, I found Intel Compute Stick. Not cheapest option, but since it's very small, the simple ease of plugging it in is hard to ignore so I ordered one.

Yes, I could get new Raspberry Pi and used that, but since I haven't used those that much, there would have been some learning curve involved with that option (including building it up with enclosure and everything else required) and here I was under time constraints here so this was the easier option.

This one came with Windows 10, unsurprisingly. When first starting Windows, it prompts you to create an user. It used to very heavily suggest "online" (networked, be it Outlook or Microsoft or whatever) account and make "offline" (local computer only) account creation kinda unobvious, so Microsoft very obviously wanted you to make a hard connection between your identity and the computer. This is very, very seriously something I absolutely refuse to do.

I've done Windows 10 install a few times now and it seems that in every release Microsoft has made the offline install a bit more difficult to do.

This time I almost couldn't. The option for local account creation just wasn't there. Only options presented were (IIRC) Outlook account or phone number.

After some attempts, it eventually occurred me to cut the wireless access (that was the previous step in installation, set up internet access) and tell the installer to "create new microsoft account" (or whatever it was). And what do you know, when it couldn't access the internet for that, I was finally presented the offline option. Victory was mine!

Only few days later I find this on hacker news. So many others have also run onto this issue and many - but not all, unfortunately - have found the same solution.

For now.

The unpleasant thought is, since Microsoft seems to be hell-bent to make every user to register to their services, at which point they try to make this mandatory. Not at once, of course. I imagine that there will be one feature update where windows will start presenting you with a nag screen every login or every few weeks to register if you're on offline account. But not until you're online, of course.

Then update or two later it will throw that screen on your face every few days. Then hours. Then it will just not go away until you do register.

I have to wonder what will my pain tolerance be when they do this... Fortunately at this point I have very few 'strings' holding me in Windows, so I could just make the leap and go Linux-only.

And kid will be getting PS4 (not that I'm happy with Sony's behavior either), so no xbox in our house either.

Make my day, Microsoft. Just try to make my day here. Do you really want me - and many others - to pull that proverbial trigger, especially since it's getting easier day by day to make that jump?