Using AN20 on PIC16LF1559

For one pet project, I decided to use Microchip’s PIC16LF1559. as it was close to perfect as far as my needs went in that particular scenario. So I got all parts, soldered it onto the board and it almost worked perfectly.

Single thing that gave me trouble was light detection. It seemed as if ADC converter was giving me nonsense. I check and rechecked my code multiple times as this was the first time I’ve dealt with this chip. It took me a while before I remembered to check errata sheet. And, lo and behold, there was an known issue: “AN20 is not internally connected to the ADC bus when AD2CON0’s CHS bit select the pin.” And guess which pin I decided to use for light sensor?

Initialization of ADC is something that will slightly vary with application but what follows is a reasonable starting point:

ADCOMCONbits.ADFM = 1;      //right-justified
ADCOMCONbits.ADCS = 0b111;  //Frc (clock derived from A/D RC oscillator)
ADCOMCONbits.ADPREF = 0b00; //Vref is Vdd
AD2CON0bits.CHS = 20;       //select AN20
AAD2CHbits.CH20 = 1;        //AN20 is connected to ADC2

This will nicely work around the issue by using AN20 on the secondary channel. Not an ideal situation but it was ok in my case as I had no other plans for secondary channel anyhow.

Reading a value is a bit different than when dealing with a usual, single-channel, setup:

uint16_t getAdcValue(void) {
    AD2CON0bits.ADON = 1; //Turn on ADC

    AD2CON0bits.GO  = 1;
    while (AD2CON0bits.GO_nDONE) { nop(); } //Wait for A/D convert complete

    AD2CON0bits.ADON = 0; //Turn off ADC

    if (AADSTATbits.AD2CONV) {
        return AD2RES1;
    } else {
        return AD2RES0;
    }
}

For my purpose it made sense to turn on/off ADC as needed - for some other scenarios it might be better just to leave it always on. But interesting bit comes when reading a value - ADC saves it interleaved between two registers: AD2RES0 and AD2RES1. Code simply had to make sure to read correct one.

And this, slightly roundabout process, finally got the project working.

VHD Attach 4.10

This is pretty much just a maintenance release of VHD Attach. No new features are present but some old bugs have been squashed. One that plenty people might have found annoying is erroneous removal of the ReFS integrity stream on NTFS drives. This makes sense when you try to create virtual disk on ReFS but has no place when dealing with NTFS.

Also registration to handle both .vhd and .vhdx is added. As this is option not turned on by default on Windows 10, not many people actually noticed it missing, but a few did. And finally there is a fix for the dreaded NullReferenceException when OpenWithProgids is not present. Neither of these really affect many systems, but it did affect some.

This is most probably the last release without the auto-upgrade functionality. I have always been proponent of software not phoning home and not making the internet connection whenever it pleases; it just seemed rude to me. However, it seems that normal people generally don’t mind, assuming it is done discretely, and it does solve my e-mail nightmare. Probably 95% percent e-mail error reports I get are due to the use of the old versions and users simply not being aware of the fix.

I am still thinking how exactly to do it and how to impact users as little as possible, considering both startup time and privacy as concerns, but do it I will. :)

As always, download is available on the program page.

Accessing NAS4Free Web Interface With SSH

Illustration

I was fortunate enough to collocate my backup machine at friend’s place. Unfortunately I wasn’t smart enough to actually setup everything. :) Only thing I had working was SSH.

Yes, my first though was to use SSH forwarding. Configuring local SSH tunnel with any free source port and using destination IP address with 443 (https) or 80 (http) as a port would allow for accessing remote web interface. Just access 127.0.0.1:localport and web interface would appear as if it was accessed through local network.

For my example I configured local port 62443 toward destination 192.168.0.1:443 and accessing 127.0.0.1:62443 should have been enough to show NAS4Free web interface. However, that didn’t work as smartass me didn’t enable Port Forwarding on the remote box. Duh!

To get out of this hole, first step is to allow for editing of config.xml where all settings are saved and that is mounted read-only by default:

umount /cf
mount -o rw /cf

After that use vi to edit /cf/conf/config.xml and add tcpforwarding configuration parameter:

<sshd>
    <port>22</port>
    <pubkeyauthentication/>
    <permitrootlogin/>
    <enable/>
    <private-key/>
    <subsystem/>
    ^^<tcpforwarding/>^^
</sshd>

Unsurprisingly that doesn’t really help as configuration isn’t applied automatically. Easiest way to apply it is restart:

init 6

As machine booted, I could access web interface via the magic of SSH port forwarding.

[2018-07-22: NAS4Free has been renamed to XigmaNAS as of July 2018]

Removing \"Custom Script Entries\" From NAS4Free Status E-mail

One annoyance I have with NAS4Free is how every custom report has a prefix - even when you fully customize it:

Custom script entries:
----------------------
All local pools are healthy
• Nenya: not reachable
• Narya: not reachable
...``

I find that “Custom script entries:” followed by dashes completely unnecessary and, if you read message on a small screen (e.g. Pebble watch), it just takes space from the more important information.

Culprit to this can be found in /etc/inc/report.inc where the following line creates that header:

$statusreport->AddArticle(new StatusReportArticleCmd("^^Custom script entries^^","{$config['statusreport']['report_scriptname']}"));

Good old sed can help us with removing this:

sed -i -e 's^Custom script entries^^g' /etc/inc/report.inc

If you have embedded installation, this will work only until restart. To make it “permanent”, just add it to SystemAdvancedCommand scripts.

[2018-07-22: NAS4Free has been renamed to XigmaNAS as of July 2018]

Uni-ball Signo 307

Illustration

Most of my writing is done on computer so I don’t use pen that often. But when I do, I pretty much always use Uni-ball Signo 207. It is a pen that has been available for ages now in multiple tip widths, my favorite being alternated between 0.5 and 0.7 millimeters. It is comfortable, has a good quality ink, a reasonable price, and it can be found pretty much anywhere. Now Uni-ball decided to give it a bit of an update with the new Signo 307.

General shape is pretty much exactly the same between those two. If 207 fits your writing style, 307 will fit too. Major difference is omitting a few metallic details found on the 207 with all-plastic design. This slightly decreased pen weight but it’s hardly noticeable. For me it had mostly visual and durability impact as the new plastic clip seems a bit more prone to breaking.

Visually it is a black barell with a nice checkered background on upper cylinder. Clicker, clip, and ring details are in the ink color. I find blue looks the best, red details are a bit too bright for me and black looks really dull. Interesting tidbit is the clip plate which has a thin plastic tooling mark on 207 but it is beautifully smooth on 307.

Clicker is a bit harder to press on the new 307 but I don’t see it as a major problem. Since spring looks identical in both you can always swap it from the 207. It also might be just a slight manufacturing difference as all my 207 were bought in previous years. If that is the case, just grow some muscles. :)

Existing Signo series gel is really smooth, nicely colored, and dries reasonably fast. Although the new Signo 307 comes with supposedly better gel formula (UMR-87E), I found no discernible difference between it and older 207 (UMR-87). Even if somehow ink update makes a difference in your case, barrels are fully compatible so you can mix and match to your liking. At this time Signo 307 is available only in 0.7 mm so those preferring thinner writing will have to stick with the 207. However, I have no doubt that other widths are going to become available in near future.

In the end, it all comes to the looks and I find Signo 307 looks are a slight improvement over 207 despite its all-plastic design. But either one will do.