Making the flex-sense assistive technology device
I’ve not detailed the build history of a project before. The design decisions made along the way, the testing of different ideas and the mistakes made are not shown. This might lead to the impression that projects went smoothly from start to finish This has never been the case! I’m putting this page together as it might help somebody not make the same mistakes I make. I’ve found it comforting to read other blogs that show the mistakes and dead ends encountered in projects. They make me feel less of a klutz!
analog to digital converter (ADC) considerations
The micro:bit has a 10 bit ADC built in. This is good as it means I don’t have to manually add one. 10 bits equates to 1024 ‘bins’ for the analog voltage to be allocated to. Sounds plenty, until we start to think about how little the voltage input to the ADC changes when the flex sensor is bent. Also, how many of these bits are usable by the microcontroller? Just because there are 10 bits, doesn’t mean that some of them are lost due to noise.
The 1024 bins are spread across the power supply range, not the small range that the voltage input to the ADC changes when the flex sensor is bent. Let’s look at this more closely.
input imepdance of the ADC
A lot of analog electronics is about the impedance characteristics between stages or of the transmission lines for signals.
As a rule of thumb, we want the impedance of the input to the ADC to be at least 10 times that of the stage that is feeding into it. The flex sensors have impedance of around 10-20 KOhm. So we want the input impedance of the ADC to be at least 200 KOhm.
Looking at the data sheet for the nRF51822:
Looking more closely at the data sheet values, we see that by altering the prescaling to be 1/3, the input impedance of the ADC is over 300 KOhm. The prescaling is how many clock cycles pass before the ADC updates. 1/3 means that the ADC updates every third clock cycle. So by reducing the frequency of ADC update, we get much better impedance characteristics.
At the default prescaling of 1/1, the input imedance is about 129 KOhm. The speed of change of the input from the flex sensor is at best 10 Hz, so we can safely use the 1/3 prescaling. Just have to figure out how to do this in the code! I suspect this is not an option in the blocks modules. Using C gives me the best bet of having the fine grain control to adjust the prescaling.
capacitor on ADC input
Adding a capacitor between the input to the ADC and ground stabilises the input voltage so that jitter in the signal is smoothed. The value of the capacitor needs to be large enough to reduce jitter and small enough that it does not introduce too much smoothing of the input signal. With the simple low frequency design presented here, we don’t need to dive too far into this. 0.1uF coupled with the roughly 10KOhm input impedance gives an RC time factor of 10^4 x 10^-7 = 10^-3 S. So we are talking about charge/discharge times for the capacitor in mS, which is about the right time scale. With the inherent capacitance associated with prototype construction, this capacitor is probably not necessary. But, you know, I have standards.