Saturday, March 31, 2012

config vs config1 explained

Recently I started to use pic18f27j53 for a robot project. I picked it since it had USB functionality, and I thought I could learn about USB through it. Just as I copy-pasted my old code from my previous robot projects, error messages began to show up on the compiler output saying that opentimer1() was missing an argument. This confused me and, upon research, I discovered that many others were confused as well. So I decided to look through the source file (t1open.c) in the C18 library to see why there were two arguments (config and config1) as opposed to just one (config1).

Well, it turns out that some of the new microchip hardware has included some new functionality called Gate Control to the timer hardware, which introduces the possibility of controlling it through external asynchronous inputs such as the comparator module. This, I think, allows users to count the duration of an input.

Anyways, for those who do not intend to use the Gate Control Hardware, config1=0 should do the trick. Since config1 controls TxGCON (Timer X Gate Control), according to the datasheet, if you set config1 to zero Gate Control will be disabled.