I eventually got this up and running based on a few snippets I found here and there, and with a little insight into the manual. Even though I seem to get the result I wanted, I am a bit frustrated that I don't really get this. Anyway; this is the working code:
void configureCounter()
{...