Close

Investigating the RFC

A project log for Sensors Based on the Padauk RFC Peripheral

Exploring the undocumented Resistance to Frequency Converter (RFC) peripheral of the Padauk PFS173 Microcontroller

timTim 09/14/2020 at 23:220 Comments

The documentation found earlier by JS provides a basic functional explanation and has a list of registers, but is a bit light on details. Nothing that can't be investigated...

The image above shows my interpretation of the "C-type" operation of the RFC. Basically it consists of a  schmitt trigger  and a ground switch. If an RC-couple (as shown) is connected between the IO-pin and the positive supply, the input voltage will slowly increase according to the RC time constant. If a certain trigger voltage is reached, the ground switch will short the input to ground until the lower trigger voltage is reached. Each time this happens, the counter increases by one. Effectively, this circuit forms a relaxation oscillator.

By evaluating the number of counts during a fixed interval, it is possible to measure changes in the capacitance or resistance.

The table above shows the register mapping. The control register allows selecting the specific pin. Bit 4 needs to be written to to start and stop the counter.

__sfr __at(0x2d)          _rfcc;
__sfr __at(0x2e)          _rfccrh;
__sfr __at(0x2f)          _rfccrl;

#define RFCC              _rfcc
#define RFCCRH            _rfccrh
#define RFCCRL            _rfccrl

 
Register mapping is shown above.  Using the RFC is rather simple, as shown below:

RFCC = 0xc0 | 0x08 | 0x02 ; // Select PB6, set to C-Mode, enable output

uint16_t result;
RFCC|= 1<<4; // start RFC
_delay_ms(50);
RFCC&=~(1<<4); // stop RFC
result=(RFCCRH<<8)|RFCCRL;


The scope picture shows the voltage on the RFC pin during operation. In this case a 100nF capacitor and 10 kOhm resistor were connected in parallel to VDD.

It can be cleary seen that the charging of the RC element follows an exponential. The upper trigger voltage is 4V, the lower trigger voltage is ~700 mV. The origin of the ringing at the lower voltage is not clear to me, it seems to be an artifact of the RFC peripheral.

The impedance of the ground switch seems to be relatively high. In this case, with the 100nF capacitor, it takes about 11 µs to discharge.

When using a lower capacitor value, the counting frequency increases propertionally. The minimum discharge time seems to be 1 IHRC cycle (IHRC was 16 MHz in this device = 62.5 ns). In that case a voltage undershoot to 0V is observed. It is clear that operation of the RC oscillator will be instable when the reset voltage is not properly defined. It seems to be advised to adjust the capacitance value so that the reset time is either below one IHRC cycle (reset voltage will be 0V), or significantly above (reset voltage will be 700 mV).

An additional parameter of interest would be how the oscillator frequency changes with supply voltage.

I measured the frequency of an oscillator with R=10 kOhm and C=100nF for different values of VDD.

It can be seen that there is a consistent variation of frequency. This is because the trigger voltages change according to the supply voltage. The lower trigger voltage seems to be defined by 0.2 * VDD, while the higher trigger voltage is defined at approximately 0.8 * VDD. The voltages are most likely directly derived from the supply with a resistive divider.

A true symmetric relaxation oscillator would not show this voltage dependence, but since the discharge is defined by the ground switch, a dependence on switching voltages is introduced. A variation of ~10% accross a 1.5 V supply difference should be good enough for many applications, though.

Great, looks like the RFC works exactly as (not) advertised. What can we use it for?

Discussions