You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bjornburton edited this page Jan 1, 2016
·
3 revisions
The Dive computer may be part of the Propulsion computer.
We need to use the ADC.
The ADC is fed by the MUX.
The MUX feeds the Input Capture of Timer 1 and must have the ADC disabled to do so.
This means that we need to enable the ADC periodically and connect is to the MUX.
The first thing to add is a timer tick at each 1/4 second.
We can use timer counter 2, our last timer.
It only has an 8 bit prescaler so it will be two fast and will need to be divided.
Set the prescaler to the maximum of 1024 by setting TCCR2B CS22, 21 & 20 (see 18.11.2).
Put the timer into CTC mode by setting TCCR2A WGM21 (see 18.11.1)
We want to divide by a power of two for efficiency and so 0x80 (0d128) is as small as we can go.
Trim the time to about 0.25 seconds by loading compare register OCR2A with 0xf3 (0d243).
Enable the interrupt by setting TIMSK2 OCIE2A.
With all that we will have interrupt TIMER2 COMPA fire every 31 ms.
That's pretty fast but should be OK.
For the software division we will increment an uint8_t in the handler on each pass and do something at 0x00 and 0x80 (0d128).
The test would be !(tickCount & ~0x80).
Motors will be controlled equally. It will proportional using the propulsion computer. Feedback will be through a pressure-Transducer. See Hold depth.