Skip to content
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

Multi-bit port support for Potentiometer mode #4

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions examples/pot_reader/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
#define FILTER_DEPTH 16
#define HYSTERESIS 1

on tile[1]: port p_adc[] = {XS1_PORT_1M, XS1_PORT_1O}; // Sets which pins are to be used (channels 0..n) X1D36/38
// Select your port as required. Either 1b or wide ports may be used.
// on tile[1]: port p_adc[] = {XS1_PORT_1M, XS1_PORT_1O}; // Sets which pins are to be used (channels 0..n) X1D36/38
on tile[1]: port p_adc[] = {XS1_PORT_4A}; // Sets which pins are to be used (channels 0..n) X1D02/03


void control_task(chanend ?c_adc, uint16_t * unsafe result_ptr){
printf("Running QADC in continuous mode using dedicated task!\n");

unsigned counter = 0;

while(1){
Expand Down Expand Up @@ -91,17 +92,20 @@ int main() {

const float v_rail = 3.3;
const float v_thresh = 1.15;
const char auto_scale = 1;
const char auto_scale = 0;

const uint16_t port_time_offset = 36; // 36 for 120MHz thread speed. Use 56 for 75MHz thread speed
const unsigned convert_interval_ticks = (1 * XS1_TIMER_KHZ); // 1 millisecond

const qadc_config_t adc_config = {capacitor_pf,
const qadc_config_t adc_config = { capacitor_pf,
potentiometer_ohms,
resistor_series_ohms,
v_rail,
v_thresh,
auto_scale,
convert_interval_ticks,
auto_scale};
port_time_offset};

qadc_pot_state_t adc_pot_state;

uint16_t state_buffer[QADC_POT_STATE_SIZE(NUM_ADC, LUT_SIZE, FILTER_DEPTH)];
Expand Down
6 changes: 4 additions & 2 deletions examples/rheo_reader/src/main.xc
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ int main() {
const char auto_scale = 0;

const unsigned convert_interval_ticks = (1 * XS1_TIMER_KHZ);

const uint16_t port_time_offset = 32; // 32 for 120MHz thread speed. Use 52 for 75MHz thread speed

const qadc_config_t adc_config = {capacitor_pf,
potentiometer_ohms,
resistor_series_ohms,
v_rail,
v_thresh,
auto_scale,
convert_interval_ticks,
auto_scale};
port_time_offset};

qadc_rheo_state_t adc_rheo_state;
uint16_t state_buffer[QADC_RHEO_STATE_SIZE(NUM_ADC, FILTER_DEPTH)];
Expand Down
9 changes: 8 additions & 1 deletion lib_qadc/api/qadc.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ typedef struct qadc_config_t{
float v_thresh;
/** The full conversion cycle time per channel (adc_xxx_task() only). The task will assert
* at initialisation if this is too short. */
char auto_scale;
/** Timing offset for the zero setting (rheostat) or end settings (potentiometer).
* This accounts for the minimum time measured by the QADC when the capacitor is already at
* the expected value but the code takes a finite time to measure this.
*
*/
unsigned convert_interval_ticks;
/** Boolean setting which allows the end points of the QADC to be stretched if the read value
* exceeds the expected value. The new end point will be kept until the task is re-started.
* This is ignored in single shot mode. */
char auto_scale;

uint16_t port_time_offset;
}qadc_config_t;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib_qadc/api/qadc_pot.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
typedef struct qadc_pot_state_t{
size_t num_adc;
unsigned port_width;
unsigned adc_idx;
size_t lut_size;
size_t filter_depth;
Expand All @@ -25,7 +26,6 @@ typedef struct qadc_pot_state_t{
qadc_q3_13_fixed_t * UNSAFE max_scale_up;
qadc_q3_13_fixed_t * UNSAFE max_scale_down;
unsigned crossover_idx;
uint32_t port_time_offset;
uint16_t * UNSAFE conversion_history;
uint16_t * UNSAFE hysteris_tracker;
uint16_t * UNSAFE init_port_val;
Expand Down
1 change: 0 additions & 1 deletion lib_qadc/api/qadc_rheo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ typedef struct qadc_rheo_state_t{
uint16_t * UNSAFE max_seen_ticks;
qadc_q3_13_fixed_t * UNSAFE max_scale;
unsigned crossover_idx;
uint16_t port_time_offset;
uint16_t * UNSAFE conversion_history;
uint16_t * UNSAFE hysteris_tracker;
uint16_t * UNSAFE filter_write_idx;
Expand Down
Loading