Page 1 of 1

Setting peripheral configuration registers in code

Posted: 16 Jun 2021 10:34
by fastbike
So, I'm looking to use a PIC16F1768/9 in a new project as it contains built in DAC and analog Comparators.

The configuration of these peripherals is done via registers. For instance if I want to invert the output of Comparator C1 I would write 1 to the C1POL bit in the CM1CON0 register (according to 19.2.3 COMPARATOR OUTPUT POLARITY in the datasheet)

Can this configuration register bit value be changed during code execution, or can it only be configured as part of the compiled program i.e. static configuration ?

Re: Setting peripheral configuration registers in code

Posted: 16 Jun 2021 11:57
by janni
CM1CON0 belongs to so-called SFRs (Special Function Registers) forming part of static RAM so it can be modified anytime. By 'configuration' registers (or words) in PIC processors one usually means a small range of nonvolatile (flash) memory where the basic processor configuration is stored and which (normally) should not be modified during program execution.

Re: Setting peripheral configuration registers in code

Posted: 16 Jun 2021 20:07
by fastbike
Thanks, it's been a while since I've worked with PICs. I've been down the Arduino road for several prototypes but needed a micro with 2 DACs and 4 comparators so the PIC family came up with the goods :)