Skip to content

Commit

Permalink
Merge branch 'main' of github.com:fossasia/pslab-firmware into frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudyPadmal committed Oct 12, 2022
2 parents 1826253 + 8946d2e commit 64c9685
Show file tree
Hide file tree
Showing 14 changed files with 2,109 additions and 2,049 deletions.
2 changes: 1 addition & 1 deletion src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ command_func_t* const cmd_table[NUM_PRIMARY_CMDS + 1][NUM_SECONDARY_CMDS_MAX + 1
// 12 READ_PROGRAM_ADDRESS 13 WRITE_PROGRAM_ADDRESS 14 READ_DATA_ADDRESS 15 WRITE_DATA_ADDRESS
Removed, Removed, DEVICE_ReadRegisterData, DEVICE_WriteRegisterData,
// 16 GET_CAP_RANGE 17 SET_RGB2 18 READ_LOG 19 RESTORE_STANDALONE
Unimplemented, Removed, Removed, DEVICE_Reset,
MULTIMETER_GetCapRange, Removed, Removed, DEVICE_Reset,
// 20 GET_ALTERNATE_HIGH_FREQUENCY 21 SET_RGB_COMMON 22 SET_RGB3 23 START_CTMU
MULTIMETER_HighFrequencyAlt, LIGHT_RGBPin, Removed, CTMU_Start,
// 24 STOP_CTMU 25 START_COUNTING 26 FETCH_COUNT 27 FILL_BUFFER
Expand Down
29 changes: 29 additions & 0 deletions src/instruments/multimeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,35 @@ response_t MULTIMETER_ChargeCapacitor(void) {
return SUCCESS;
}

response_t MULTIMETER_GetCapRange(void) {

uint16_t charge_time = UART1_ReadInt();

ChargeCapacitor(CHARGE, 50000);

ADC1_SetOperationMode(ADC1_12BIT_AVERAGING_MODE, CH0_CHANNEL_CAP, 0);

TMR5_Initialize();
TMR5_Period16BitSet(charge_time);
TMR5_SetPrescaler(TMR_PRESCALER_64);
TMR5_Start();

// Start charging the capacitor through 10K resistor
CAP_OUT_SetDigitalOutput();
CAP_OUT_SetHigh();

TMR5_WaitForInterruptEvent();

// Stop the charging process
CAP_OUT_SetDigitalInput();
CAP_OUT_SetLow();

uint16_t range = GetVoltage_Summed(CH0_CHANNEL_CAP);
UART1_WriteInt(range);

return SUCCESS;
}

response_t MULTIMETER_GetCapacitance(void) {

uint8_t current_range = UART1_Read();
Expand Down
16 changes: 16 additions & 0 deletions src/instruments/multimeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ extern "C" {
*/
response_t MULTIMETER_LowFrequency(void);

/**
* @brief Get an estimate of the capacitor range
*
* @description
* This function can be used to get an estimate of how large a
* capacitor is. One use case could be to compare two different
* capacitors without having to evaluate the exact capacitance.
* This command takes only one argument over serial:
* 1. (uint16) Charge time in micro seconds
*
* It returns the range value as uint16.
*
* @return SUCCESS
*/
response_t MULTIMETER_GetCapRange(void);

/**
* @brief Measurements using Charge Time Measurement Unit
*
Expand Down
Loading

0 comments on commit 64c9685

Please sign in to comment.