Skip to content

Commit 64c9685

Browse files
committed
Merge branch 'main' of github.com:fossasia/pslab-firmware into frequency
2 parents 1826253 + 8946d2e commit 64c9685

File tree

14 files changed

+2109
-2049
lines changed

14 files changed

+2109
-2049
lines changed

src/commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1
252252
// 12 READ_PROGRAM_ADDRESS 13 WRITE_PROGRAM_ADDRESS 14 READ_DATA_ADDRESS 15 WRITE_DATA_ADDRESS
253253
Removed, Removed, DEVICE_ReadRegisterData, DEVICE_WriteRegisterData,
254254
// 16 GET_CAP_RANGE 17 SET_RGB2 18 READ_LOG 19 RESTORE_STANDALONE
255-
Unimplemented, Removed, Removed, DEVICE_Reset,
255+
MULTIMETER_GetCapRange, Removed, Removed, DEVICE_Reset,
256256
// 20 GET_ALTERNATE_HIGH_FREQUENCY 21 SET_RGB_COMMON 22 SET_RGB3 23 START_CTMU
257257
MULTIMETER_HighFrequencyAlt, LIGHT_RGBPin, Removed, CTMU_Start,
258258
// 24 STOP_CTMU 25 START_COUNTING 26 FETCH_COUNT 27 FILL_BUFFER

src/instruments/multimeter.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,35 @@ response_t MULTIMETER_ChargeCapacitor(void) {
164164
return SUCCESS;
165165
}
166166

167+
response_t MULTIMETER_GetCapRange(void) {
168+
169+
uint16_t charge_time = UART1_ReadInt();
170+
171+
ChargeCapacitor(CHARGE, 50000);
172+
173+
ADC1_SetOperationMode(ADC1_12BIT_AVERAGING_MODE, CH0_CHANNEL_CAP, 0);
174+
175+
TMR5_Initialize();
176+
TMR5_Period16BitSet(charge_time);
177+
TMR5_SetPrescaler(TMR_PRESCALER_64);
178+
TMR5_Start();
179+
180+
// Start charging the capacitor through 10K resistor
181+
CAP_OUT_SetDigitalOutput();
182+
CAP_OUT_SetHigh();
183+
184+
TMR5_WaitForInterruptEvent();
185+
186+
// Stop the charging process
187+
CAP_OUT_SetDigitalInput();
188+
CAP_OUT_SetLow();
189+
190+
uint16_t range = GetVoltage_Summed(CH0_CHANNEL_CAP);
191+
UART1_WriteInt(range);
192+
193+
return SUCCESS;
194+
}
195+
167196
response_t MULTIMETER_GetCapacitance(void) {
168197

169198
uint8_t current_range = UART1_Read();

src/instruments/multimeter.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ extern "C" {
100100
*/
101101
response_t MULTIMETER_LowFrequency(void);
102102

103+
/**
104+
* @brief Get an estimate of the capacitor range
105+
*
106+
* @description
107+
* This function can be used to get an estimate of how large a
108+
* capacitor is. One use case could be to compare two different
109+
* capacitors without having to evaluate the exact capacitance.
110+
* This command takes only one argument over serial:
111+
* 1. (uint16) Charge time in micro seconds
112+
*
113+
* It returns the range value as uint16.
114+
*
115+
* @return SUCCESS
116+
*/
117+
response_t MULTIMETER_GetCapRange(void);
118+
103119
/**
104120
* @brief Measurements using Charge Time Measurement Unit
105121
*

0 commit comments

Comments
 (0)