-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ctmu capacitance measurement #104
feat: ctmu capacitance measurement #104
Conversation
// Switch to high impedance state | ||
CAP_OUT_SetDigitalInput(); | ||
CAP_OUT_SetAnalog(); | ||
Nop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, what is the purpose of Nop
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, I'm not sure. It's as it is from the original source. Need to test out the parts thoroughly and see if we can remove.
return SUCCESS; | ||
} | ||
|
||
response_t MULTIMETER_ReadCapacitance(void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is quite large. It would benefit from being split up into more atomic units, I think.
// TODO: Check the viability of the following block as it does nothing important | ||
CAP_OUT_SetDigitalOutput(); | ||
CAP_OUT_SetDigital(); | ||
CAP_OUT_SetLow(); | ||
DELAY_us(50000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the purpose of this block is to ensure the capacitor is fully discharged before starting the measurement.
@@ -138,7 +138,17 @@ void ADC1_SetOperationMode( | |||
AD1CON3bits.ADCS = 0b00001010; // TAD = Tp*10 = 156.25 ns | |||
break; | |||
case ADC1_CTMU_MODE: | |||
// initADCCTMU() | |||
// Disable DMA channel | |||
DMA0CONbits.CHEN = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use auto generated function DMA_ChannelDisable(DMA_CHANNEL_0)
here.
ADC1_ChannelSelectSet(current_channel_0); | ||
// Clock settings | ||
AD1CON3bits.SAMC = 0b10000; // 16*TAD auto sample time | ||
AD1CON3bits.ADCS = 0b00001010; // TAD = Tp*10 = 156.25 ns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we could use ADC1_ConversionClockPrescalerSet
instead.
Thanks alot for the review @bessman . I'll make the changes soon and push them here. |
69baf8a
to
b9052ea
Compare
6cb9da0
to
6fc80a9
Compare
Build fails due to Codacy analysis. It doesn't capture the fact that |
ef3c242
to
091c5ee
Compare
TMR5_Stop(); | ||
T5CONbits.TSIDL = 1; | ||
T5CONbits.TCKPS = 1; | ||
TMR5 = 0; | ||
TMR5_Start(); | ||
_T5IF = 0; | ||
_T5IE = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed. InitModesCommon
is called by Init10BitMode
and InitDMAMode
, which in turn are only called by the OSCILLOSCOPE module, which resets the timer after this point anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a mistake while rebasing the working branch. InitModesCommon
shouldn't be touched by this PR. I'll update it.
|
||
#define MAX_CHANNELS 4 | ||
|
||
/* Static globals */ | ||
static uint8_t volatile TRIGGERED = 0; | ||
static uint8_t volatile TRIGGER_READY = 0; | ||
static uint8_t TRIGGER_CHANNEL = 0; | ||
static uint8_t CHANNELS = 0; | ||
static uint8_t CONVERSION_DONE = 1; | ||
|
||
static uint16_t DELAY; | ||
static const uint16_t TRIGGER_TIMEOUT = 50000; | ||
static uint16_t volatile TRIGGER_WAITING = 0; | ||
static uint16_t TRIGGER_LEVEL = 0; | ||
static uint16_t TRIGGER_PRESCALER = 0; | ||
|
||
static int16_t volatile* volatile BUFFER_IDX[MAX_CHANNELS]; | ||
static uint16_t volatile* ADCVALS[MAX_CHANNELS] = { | ||
&ADC1BUF0, &ADC1BUF1, &ADC1BUF2, &ADC1BUF3 | ||
}; | ||
static uint16_t volatile SAMPLES_CAPTURED; | ||
static uint16_t SAMPLES_REQUESTED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge fan of this. Would be better if these were in adc.c and we added public getters and setters for them. I think that would also solve the Codacy complaint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Couldn't think of an efficient and "easy" way to sort out this variable set. Let's try getters and setters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think the function names should be for getters and setters? Get_VAR()
or GetVAR()
or getVAR()
? 🤔
98d2320
to
b1afd5f
Compare
b1afd5f
to
cca2197
Compare
cca2197
to
351efbf
Compare
Replaced #102