Rev 3 DAC updates

This commit is contained in:
Kevin Santo Cappuccio 2023-08-12 15:12:32 -07:00
parent 1ed486ac6e
commit 4eaf13571b
8 changed files with 1016 additions and 224 deletions

BIN
Hardware/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,676 @@
{
"board": {
"3dviewports": [],
"design_settings": {
"defaults": {
"board_outline_line_width": 0.09999999999999999,
"copper_line_width": 0.19999999999999998,
"copper_text_italic": false,
"copper_text_size_h": 1.5,
"copper_text_size_v": 1.5,
"copper_text_thickness": 0.3,
"copper_text_upright": false,
"courtyard_line_width": 0.049999999999999996,
"dimension_precision": 4,
"dimension_units": 3,
"dimensions": {
"arrow_length": 1270000,
"extension_offset": 500000,
"keep_text_aligned": true,
"suppress_zeroes": false,
"text_position": 0,
"units_format": 1
},
"fab_line_width": 0.09999999999999999,
"fab_text_italic": false,
"fab_text_size_h": 1.0,
"fab_text_size_v": 1.0,
"fab_text_thickness": 0.15,
"fab_text_upright": false,
"other_line_width": 0.15,
"other_text_italic": false,
"other_text_size_h": 1.0,
"other_text_size_v": 1.0,
"other_text_thickness": 0.15,
"other_text_upright": false,
"pads": {
"drill": 0.0,
"height": 0.7,
"width": 0.7
},
"silk_line_width": 0.15,
"silk_text_italic": false,
"silk_text_size_h": 1.0,
"silk_text_size_v": 1.0,
"silk_text_thickness": 0.15,
"silk_text_upright": false,
"zones": {
"min_clearance": 0.0
}
},
"diff_pair_dimensions": [
{
"gap": 0.0,
"via_gap": 0.0,
"width": 0.0
}
],
"drc_exclusions": [],
"meta": {
"version": 2
},
"rule_severities": {
"annular_width": "error",
"clearance": "warning",
"connection_width": "warning",
"copper_edge_clearance": "error",
"copper_sliver": "warning",
"courtyards_overlap": "ignore",
"diff_pair_gap_out_of_range": "error",
"diff_pair_uncoupled_length_too_long": "error",
"drill_out_of_range": "error",
"duplicate_footprints": "warning",
"extra_footprint": "warning",
"footprint": "error",
"footprint_type_mismatch": "ignore",
"hole_clearance": "error",
"hole_near_hole": "error",
"invalid_outline": "error",
"isolated_copper": "warning",
"item_on_disabled_layer": "error",
"items_not_allowed": "error",
"length_out_of_range": "error",
"lib_footprint_issues": "warning",
"lib_footprint_mismatch": "warning",
"malformed_courtyard": "error",
"microvia_drill_out_of_range": "error",
"missing_courtyard": "ignore",
"missing_footprint": "warning",
"net_conflict": "warning",
"npth_inside_courtyard": "ignore",
"padstack": "warning",
"pth_inside_courtyard": "ignore",
"shorting_items": "error",
"silk_edge_clearance": "ignore",
"silk_over_copper": "ignore",
"silk_overlap": "warning",
"skew_out_of_range": "error",
"solder_mask_bridge": "error",
"starved_thermal": "error",
"text_height": "ignore",
"text_thickness": "ignore",
"through_hole_pad_without_hole": "error",
"too_many_vias": "error",
"track_dangling": "warning",
"track_width": "error",
"tracks_crossing": "error",
"unconnected_items": "error",
"unresolved_variable": "error",
"via_dangling": "warning",
"zones_intersect": "error"
},
"rules": {
"max_error": 0.005,
"min_clearance": 0.06,
"min_connection": 0.0,
"min_copper_edge_clearance": 0.25,
"min_hole_clearance": 0.15,
"min_hole_to_hole": 0.25,
"min_microvia_diameter": 0.19999999999999998,
"min_microvia_drill": 0.09999999999999999,
"min_resolved_spokes": 1,
"min_silk_clearance": 0.0,
"min_text_height": 0.7999999999999999,
"min_text_thickness": 0.12,
"min_through_hole_diameter": 0.15,
"min_track_width": 0.08,
"min_via_annular_width": 0.075,
"min_via_diameter": 0.19999999999999998,
"solder_mask_clearance": 0.0,
"solder_mask_min_width": 0.0,
"solder_mask_to_copper_clearance": 0.0,
"use_height_for_length_calcs": true
},
"teardrop_options": [
{
"td_allow_use_two_tracks": true,
"td_curve_segcount": 5,
"td_on_pad_in_zone": false,
"td_onpadsmd": true,
"td_onroundshapesonly": false,
"td_ontrackend": false,
"td_onviapad": true
}
],
"teardrop_parameters": [
{
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_target_name": "td_round_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_target_name": "td_rect_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_target_name": "td_track_end",
"td_width_to_size_filter_ratio": 0.9
}
],
"track_widths": [
0.0,
0.15,
0.2,
0.25,
0.3,
0.8
],
"via_dimensions": [
{
"diameter": 0.0,
"drill": 0.0
},
{
"diameter": 0.25,
"drill": 0.15
},
{
"diameter": 0.3,
"drill": 0.15
},
{
"diameter": 0.3,
"drill": 0.2
},
{
"diameter": 0.35,
"drill": 0.15
},
{
"diameter": 0.4,
"drill": 0.2
}
],
"zones_allow_external_fillets": false
},
"layer_presets": [],
"viewports": []
},
"boards": [],
"cvpcb": {
"equivalence_files": []
},
"erc": {
"erc_exclusions": [],
"meta": {
"version": 0
},
"pin_map": [
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
1,
0,
1,
2
],
[
0,
1,
0,
0,
0,
0,
1,
1,
2,
1,
1,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
2
],
[
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
1,
2
],
[
0,
0,
0,
1,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
1,
2,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
0,
2,
1,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2
]
],
"rule_severities": {
"bus_definition_conflict": "error",
"bus_entry_needed": "error",
"bus_to_bus_conflict": "error",
"bus_to_net_conflict": "error",
"conflicting_netclasses": "error",
"different_unit_footprint": "error",
"different_unit_net": "error",
"duplicate_reference": "error",
"duplicate_sheet_names": "error",
"endpoint_off_grid": "warning",
"extra_units": "error",
"global_label_dangling": "warning",
"hier_label_mismatch": "error",
"label_dangling": "error",
"lib_symbol_issues": "warning",
"missing_bidi_pin": "warning",
"missing_input_pin": "warning",
"missing_power_pin": "error",
"missing_unit": "warning",
"multiple_net_names": "warning",
"net_not_bus_member": "warning",
"no_connect_connected": "warning",
"no_connect_dangling": "warning",
"pin_not_connected": "error",
"pin_not_driven": "error",
"pin_to_pin": "error",
"power_pin_not_driven": "error",
"similar_labels": "warning",
"simulation_model_issue": "error",
"unannotated": "error",
"unit_value_mismatch": "error",
"unresolved_variable": "error",
"wire_dangling": "error"
}
},
"libraries": {
"pinned_footprint_libs": [],
"pinned_symbol_libs": []
},
"meta": {
"filename": "Jumperless2.kicad_pro",
"version": 1
},
"net_settings": {
"classes": [
{
"bus_width": 12,
"clearance": 0.1,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Default",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.15,
"via_diameter": 0.3,
"via_drill": 0.15,
"wire_width": 6
},
{
"bus_width": 12,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Normal",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.2,
"via_diameter": 0.3,
"via_drill": 0.15,
"wire_width": 6
},
{
"bus_width": 12,
"clearance": 0.1,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Power",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.2,
"via_diameter": 0.35,
"via_drill": 0.2,
"wire_width": 6
},
{
"bus_width": 12,
"clearance": 0.09,
"diff_pair_gap": 0.127,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.1,
"line_style": 0,
"microvia_diameter": 0.25,
"microvia_drill": 0.15,
"name": "Small",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.1,
"via_diameter": 0.25,
"via_drill": 0.15,
"wire_width": 6
}
],
"meta": {
"version": 3
},
"net_colors": null,
"netclass_assignments": null,
"netclass_patterns": [
{
"netclass": "Power",
"pattern": "+3V3"
},
{
"netclass": "Power",
"pattern": "+5V"
},
{
"netclass": "Power",
"pattern": "GND"
},
{
"netclass": "Power",
"pattern": "+8V"
},
{
"netclass": "Power",
"pattern": "-8V"
},
{
"netclass": "Power",
"pattern": "+9V"
},
{
"netclass": "Power",
"pattern": "-9V"
},
{
"netclass": "Power",
"pattern": "DAC*"
},
{
"netclass": "Power",
"pattern": "CURR*"
},
{
"netclass": "Power",
"pattern": "ADC*"
},
{
"netclass": "Power",
"pattern": "I*"
},
{
"netclass": "Power",
"pattern": "T*"
},
{
"netclass": "Power",
"pattern": "BO*"
},
{
"netclass": "Power",
"pattern": "1*"
},
{
"netclass": "Power",
"pattern": "2*"
},
{
"netclass": "Power",
"pattern": "3*"
},
{
"netclass": "Power",
"pattern": "4*"
},
{
"netclass": "Power",
"pattern": "5*"
},
{
"netclass": "Power",
"pattern": "6*"
},
{
"netclass": "Power",
"pattern": "7*"
},
{
"netclass": "Power",
"pattern": "8*"
},
{
"netclass": "Power",
"pattern": "9*"
},
{
"netclass": "Power",
"pattern": ""
},
{
"netclass": "Power",
"pattern": ""
},
{
"netclass": "Power",
"pattern": "Net-(D100-V*"
}
]
},
"pcbnew": {
"last_paths": {
"gencad": "",
"idf": "",
"netlist": "",
"specctra_dsn": "",
"step": "../../Jumperless2.step",
"vrml": "../../Jumperless2.wrl"
},
"page_layout_descr_file": ""
},
"schematic": {
"annotate_start_num": 0,
"drawing": {
"dashed_lines_dash_length_ratio": 12.0,
"dashed_lines_gap_length_ratio": 3.0,
"default_line_thickness": 6.0,
"default_text_size": 50.0,
"field_names": [],
"intersheets_ref_own_page": false,
"intersheets_ref_prefix": "",
"intersheets_ref_short": false,
"intersheets_ref_show": false,
"intersheets_ref_suffix": "",
"junction_size_choice": 3,
"label_size_ratio": 0.375,
"pin_symbol_size": 25.0,
"text_offset_ratio": 0.15
},
"legacy_lib_dir": "",
"legacy_lib_list": [],
"meta": {
"version": 1
},
"net_format_name": "",
"ngspice": {
"fix_include_paths": true,
"meta": {
"version": 0
},
"model_mode": 0,
"workbook_filename": ""
},
"page_layout_descr_file": "",
"plot_directory": "../../",
"spice_adjust_passive_values": false,
"spice_current_sheet_as_root": false,
"spice_external_command": "spice \"%I\"",
"spice_model_current_sheet_as_root": true,
"spice_save_all_currents": false,
"spice_save_all_voltages": false,
"subpart_first_id": 65,
"subpart_id_separator": 0
},
"sheets": [
[
"8ec97ee2-81b7-42dd-ac8f-66899dc25929",
""
]
],
"text_variables": {}
}

View File

@ -691,25 +691,25 @@ void debugFlagInit(void)
#endif
if (debugFP != 0 && debugFP != 1)
EEPROM.write(DEBUG_FILEPARSINGADDRESS, 1);
EEPROM.write(DEBUG_FILEPARSINGADDRESS, 0);
if (debugFPtime != 0 && debugFPtime != 1)
EEPROM.write(TIME_FILEPARSINGADDRESS, 1);
EEPROM.write(TIME_FILEPARSINGADDRESS, 0);
if (debugNM != 0 && debugNM != 1)
EEPROM.write(DEBUG_NETMANAGERADDRESS, 1);
EEPROM.write(DEBUG_NETMANAGERADDRESS, 0);
if (debugNMtime != 0 && debugNMtime != 1)
EEPROM.write(TIME_NETMANAGERADDRESS, 1);
EEPROM.write(TIME_NETMANAGERADDRESS, 0);
if (debugNTCC != 0 && debugNTCC != 1)
EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 1);
EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 0);
if (debugNTCC2 != 0 && debugNTCC2 != 1)
EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 1);
EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 0);
if (debugLEDs != 0 && debugLEDs != 1)
EEPROM.write(DEBUG_LEDSADDRESS, 1);
EEPROM.write(DEBUG_LEDSADDRESS, 0);
if (LEDbrightnessRail < 0 || LEDbrightnessRail > 200)
{

View File

@ -630,9 +630,12 @@ void lightUpNet(int netNumber, int node, int onOff, int brightness2, int hueShif
if (net[netNumber].nodes[j] >= NANO_D0 && net[netNumber].nodes[j] <= NANO_A7)
{
pcbExtinction = PCBEXTINCTION;
//Serial.println (brightness2);
// hueShift += PCBHUESHIFT;
// colorCorrection = 1;
}
//pcbExtinction += (brightness2-DEFAULTBRIGHTNESS);
struct rgbColor colorToShift = {net[netNumber].color.r, net[netNumber].color.g, net[netNumber].color.b};
@ -647,8 +650,14 @@ void lightUpNet(int netNumber, int node, int onOff, int brightness2, int hueShif
if (net[netNumber].specialFunction >= 100 && net[netNumber].specialFunction <= 105)
{
shiftedColorHsv.v = LEDbrightnessRail;
if (brightness2 != DEFAULTBRIGHTNESS)
{
shiftedColorHsv.v = brightness2;
}
else
{
shiftedColorHsv.v = LEDbrightnessRail;
}
shiftedColor = HsvToRgb(shiftedColorHsv);
color = packRgb(shiftedColor.r, shiftedColor.g, shiftedColor.b);
@ -658,7 +667,15 @@ void lightUpNet(int netNumber, int node, int onOff, int brightness2, int hueShif
}
else if (net[netNumber].specialFunction >= 106 && net[netNumber].specialFunction <= 120)
{
shiftedColorHsv.v = LEDbrightnessSpecial;
if (brightness2 != DEFAULTBRIGHTNESS)
{
shiftedColorHsv.v = brightness2;
}
else
{
shiftedColorHsv.v = LEDbrightnessSpecial;
}
shiftedColor = HsvToRgb(shiftedColorHsv);
color = packRgb(shiftedColor.r, shiftedColor.g, shiftedColor.b);
@ -666,7 +683,15 @@ void lightUpNet(int netNumber, int node, int onOff, int brightness2, int hueShif
}
else
{
shiftedColorHsv.v = LEDbrightness;
if (brightness2 != DEFAULTBRIGHTNESS)
{
shiftedColorHsv.v = brightness2;
}
else
{
shiftedColorHsv.v = LEDbrightness;
}
shiftedColor = HsvToRgb(shiftedColorHsv);
color = packRgb(shiftedColor.r, shiftedColor.g, shiftedColor.b);

View File

@ -19,6 +19,8 @@
#include "mcp4725.hpp"
#include "MCP_DAC.h"
#include <SPI.h>
#define DAC_RESOLUTION 9
int revisionNumber = 0;
@ -34,17 +36,15 @@ uint32_t halvePeriod[3] = {0, 0, 0};
// r = random
char mode[3] = {'z', 'z', 'z'};
int dacOn[3] = {0, 0, 0};
int amplitude[3] = {4095, 3500, 0};
int offset[3] = {2047, 1932, 2047};
int calib[3] = {-10, 150, 0};
int dacOn[3] = {0, 0, 0};
int amplitude[3] = {4095, 3763, 0};
int offset[3] = {2047, 2380, 2047};
int calib[3] = {-10, 0, 0};
MCP4725_PICO dac0_5V(5.0);
MCP4725_PICO dac1_8V(18.0);
MCP_DAC dac_rev3; //A is dac0 B is dac1
MCP4822 dac_rev3; // A is dac0 B is dac1
INA219 INA0(0x40);
INA219 INA1(0x41);
@ -77,44 +77,63 @@ void initADC(void)
void initDAC(void)
{
// Wire.begin();
if (dac1_8V.begin(MCP4725A1_Addr_A01, i2c0, 3000, 4, 5) == true)
{
revisionNumber = 2;
dac0_5V.begin(MCP4725A1_Addr_A00, i2c0, 3000, 4, 5);
{
revisionNumber = 2;
//
delay(1);
dac0_5V.setVoltage(0.00,MCP4725_EEPROM_Mode,MCP4725_PowerDown_Off);
delay(1);
dac0_5V.setVoltage(0.00);
//dac0_5V.setInputCode(0,MCP4725_EEPROM_Mode,MCP4725_PowerDown_Off);
delay(1);
dac1_8V.setInputCode(offset[1] + calib[1],MCP4725_EEPROM_Mode,MCP4725_PowerDown_Off);
delay(1);
dac1_8V.setInputCode(offset[1] + calib[1]);
} else {
revisionNumber = 3;
//dac_rev3.begin();
setDac0_5V(0.00);
setDac1_8V(0.00);
amplitude[1] = 3500;
offset[1] = 1932;
calib[1] = 150;
}
dac0_5V.begin(MCP4725A1_Addr_A00, i2c0, 3000, 4, 5);
//
delay(1);
dac0_5V.setVoltage(0.00, MCP4725_EEPROM_Mode, MCP4725_PowerDown_Off);
delay(1);
dac0_5V.setVoltage(0.00);
// setDac0_5VinputCode(0,MCP4725_EEPROM_Mode,MCP4725_PowerDown_Off);
delay(1);
dac1_8V.setInputCode(offset[1] + calib[1], MCP4725_EEPROM_Mode, MCP4725_PowerDown_Off);
delay(1);
dac1_8V.setInputCode(offset[1] + calib[1]);
}
else
{
revisionNumber = 3;
// dac_rev3.begin();
// setRX(pin_size_t pin);
SPI.setRX(0);
SPI.setCS(1);
SPI.setSCK(2);
SPI.setTX(3);
SPI.begin();
// dac_rev3.maxValue = 4095;
dac_rev3.setGain(2);
dac_rev3.begin(1);
delay(5);
setDac0_5Vvoltage(0.00);
setDac1_8VinputCode(4095);
}
}
void initINA219(void)
{
// delay(3000);
//Serial.println(__FILE__);
//Serial.print("INA219_LIB_VERSION: ");
//Serial.println(INA219_LIB_VERSION);
// Serial.println(__FILE__);
// Serial.print("INA219_LIB_VERSION: ");
// Serial.println(INA219_LIB_VERSION);
//Wire.begin();
//Wire.setClock(1000000);
// Wire.begin();
// Wire.setClock(1000000);
Wire.begin();
if (!INA0.begin() || !INA1.begin())
@ -125,8 +144,6 @@ void initINA219(void)
INA0.setMaxCurrentShunt(1, 2);
INA1.setMaxCurrentShunt(1, 2);
Serial.println(INA0.setBusVoltageRange(16));
Serial.println(INA1.setBusVoltageRange(16));
}
@ -139,136 +156,127 @@ void dacSine(int resolution)
case 0 ... 5:
for (i = 0; i < 32; i++)
{
dac1_8V.setInputCode(DACLookup_FullSine_5Bit[i]);
setDac1_8VinputCode(DACLookup_FullSine_5Bit[i]);
}
break;
case 6:
for (i = 0; i < 64; i++)
{
dac1_8V.setInputCode(DACLookup_FullSine_6Bit[i]);
setDac1_8VinputCode(DACLookup_FullSine_6Bit[i]);
}
break;
case 7:
for (i = 0; i < 128; i++)
{
dac1_8V.setInputCode(DACLookup_FullSine_7Bit[i]);
setDac1_8VinputCode(DACLookup_FullSine_7Bit[i]);
}
break;
case 8:
for (i = 0; i < 256; i++)
{
dac1_8V.setInputCode(DACLookup_FullSine_8Bit[i]);
setDac1_8VinputCode(DACLookup_FullSine_8Bit[i]);
}
break;
case 9 ... 12:
for (i = 0; i < 512; i++)
{
dac1_8V.setInputCode(DACLookup_FullSine_9Bit[i]);
setDac1_8VinputCode(DACLookup_FullSine_9Bit[i]);
}
break;
}
}
void setDac0_5V(float voltage)
uint16_t lastInputCode0 = 0;
uint16_t lastInputCode1 = offset[1] + calib[1];
void setDac0_5Vvoltage(float voltage)
{
if (revisionNumber == 2) {
dac0_5V.setVoltage(voltage);
} else {
int voltageCode = voltage * 4095 / 5;
dac_rev3.fastWriteA(voltageCode);
}
}
void setDac1_8V(float voltage)
{
if (revisionNumber == 2) {
dac1_8V.setVoltage(voltage);
} else {
int voltageCode = voltage * 4095 / 16;
voltageCode = voltageCode + 2048;
dac_rev3.fastWriteB(voltageCode);
}
}
void refillTable(int amplitude, int offset, int dac)
{
// int offsetCorr = 0;
if (dac == 0)
if (revisionNumber == 2)
{
// offset = amplitude / 2;
dac0_5V.setVoltage(voltage);
}
for (int i = 0; i < 360; i++)
else
{
if (dac == 0)
{
sine0[i] = offset + round(amplitude / 2 * sin(i * PI / 180));
}
else if (dac == 1)
{
sine1[i] = offset + round(amplitude / 2 * sin(i * PI / 180));
}
else if (dac == 2)
{
sine0[i] = offset + round(amplitude / 2 * sin(i * PI / 180));
sine1[i] = offset + round(amplitude / 2 * sin(i * PI / 180));
}
int voltageCode = voltage * 4095 / 5;
// dac_rev3.analogWrite((uint16_t)voltageCode, 0);
dac_rev3.fastWriteA((uint16_t)voltageCode);
lastInputCode0 = voltageCode;
dac_rev3.fastWriteB(lastInputCode1);
}
}
void GetAdc29Status(int i)
void setDac0_5VinputCode(uint16_t inputCode)
{
gpio_function gpio29Function = gpio_get_function(29);
Serial.print("GPIO29 func: ");
Serial.println(gpio29Function);
bool pd = gpio_is_pulled_down(29);
Serial.print("GPIO29 pd: ");
Serial.println(pd);
bool h = gpio_is_input_hysteresis_enabled(29);
Serial.print("GPIO29 h: ");
Serial.println(h);
gpio_slew_rate slew = gpio_get_slew_rate(29);
Serial.print("GPIO29 slew: ");
Serial.println(slew);
gpio_drive_strength drive = gpio_get_drive_strength(29);
Serial.print("GPIO29 drive: ");
Serial.println(drive);
int irqmask = gpio_get_irq_event_mask(29);
Serial.print("GPIO29 irqmask: ");
Serial.println(irqmask);
bool out = gpio_is_dir_out(29);
Serial.print("GPIO29 out: ");
Serial.println(out);
Serial.printf("(%i) GPIO29 func: %i, pd: %i, h: %i, slew: %i, drive: %i, irqmask: %i, out: %i\n", i, gpio29Function, pd, h, slew, drive, irqmask, out);
if (revisionNumber == 2)
{
dac0_5V.setInputCode(inputCode);
}
else
{
dac_rev3.analogWrite(inputCode, 0);
dac_rev3.fastWriteA(inputCode);
lastInputCode0 = inputCode;
dac_rev3.fastWriteB(lastInputCode1);
}
}
float readAdc(int channel, int samples)
void setDac1_8Vvoltage(float voltage)
{
if (revisionNumber == 2)
{
dac1_8V.setVoltage(voltage);
}
else
{
int voltageCode = voltage * 4095 / 16;
voltageCode = voltageCode + 2048;
// dac_rev3.analogWrite((uint16_t)voltageCode, 1);
dac_rev3.fastWriteB((uint16_t)voltageCode);
lastInputCode1 = voltageCode;
dac_rev3.fastWriteA(lastInputCode0);
}
}
void setDac1_8VinputCode(uint16_t inputCode)
{
if (revisionNumber == 2)
{
dac1_8V.setInputCode(inputCode);
}
else
{
// Serial.println(inputCode);
// dac_rev3.analogWrite(inputCode, 1);
dac_rev3.fastWriteB(inputCode);
lastInputCode1 = inputCode;
dac_rev3.fastWriteA(lastInputCode0);
}
}
int readAdc(int channel, int samples)
{
int adcReadingAverage = 0;
for (int i = 0; i < 20; i++)
for (int i = 0; i < samples; i++)
{
adcReadingAverage += analogRead(28);
delay(5);
adcReadingAverage += analogRead(channel);
delay(1);
}
int adc3Reading = adcReadingAverage / 20;
Serial.print(adc3Reading);
int adc3Reading = adcReadingAverage / samples;
// Serial.print(adc3Reading);
float adc3Voltage = (adc3Reading - 2528) / 220.0; // painstakingly measured
return adc3Voltage;
// float adc3Voltage = (adc3Reading - 2528) / 220.0; // painstakingly measured
return adc3Reading;
}
int waveGen(void)
{
int loopCounter = 0;
listSpecialNets();
listNets();
@ -279,16 +287,18 @@ int waveGen(void)
mode[1] = 's';
mode[2] = 's';
refillTable(amplitude[0], offset[0] + calib[0], 0);
refillTable(amplitude[1], offset[1] + calib[1], 1);
if (dac0_5V.setVoltage(0.0) == false)
{
Serial.println("dac0_5V.setVoltage() failed");
}
dac1_8V.setInputCode(offset[1] + calib[1]);
setDac0_5Vvoltage(0.0);
setDac1_8VinputCode(offset[1] + calib[1]);
// setDac1_8VinputCode(8190);
// Serial.println(dac_rev3.getGain());
Serial.println(dac_rev3.maxValue());
Serial.print("Revision = ");
Serial.println(revisionNumber);
Serial.println("\n\r\t\t\t\t waveGen\t\n\n\r\toptions\t\t\twaves\t\t\tadjust frequency\n\r");
Serial.println("\t5/0 = dac 0 0-5V (togg)\tq = square\t\t+ = frequency++\n\r");
Serial.println("\t8/1 = dac 1 +-8V (togg)\ts = sine\t\t- = frequency--\n\r");
@ -302,6 +312,10 @@ int waveGen(void)
int chars = 0;
chars = 0;
int firstCrossFreq0 = 0;
int firstCrossFreq1 = 0;
while (1)
{
yield();
@ -312,74 +326,90 @@ int waveGen(void)
// float adc3Voltage = (adc3Reading - 2528) / 220.0; //painstakingly measured
// float adc0Voltage = ((adc0Reading) / 400.0) - 0.69; //- 0.93; //painstakingly measured
int adc0Reading = 0;
int brightness0 = 0;
int hueShift0 = 0;
int adc0Reading = 0;
int brightness0 = 0;
int hueShift0 = 0;
//firstCrossFreq0 = 1;
if (dacOn[0] == 1)
if (dacOn[0] == 1&& freq[0] < 33)
{
adc0Reading = INA1.getBusVoltage_mV();
// adc0Reading = dac0_5V.getInputCode();
adc0Reading = abs(adc0Reading);
hueShift0 = map(adc0Reading, 0, 5000, -90, 0);
brightness0 = map(adc0Reading, 0, 5000, 4, 100);
lightUpNet(4, -1, 1, brightness0, hueShift0);
showLEDsCore2 = 1;
firstCrossFreq0 = 1;
}
else
{
if (firstCrossFreq0 == 1)
{
adc0Reading = INA1.getBusVoltage_mV();
//adc0Reading = dac0_5V.getInputCode();
adc0Reading = abs(adc0Reading );
hueShift0 = map(adc0Reading, 0, 5000, -90, 0);
} else {
adc0Reading = amplitude[0];
lightUpNet(4);
showLEDsCore2 = 1;
firstCrossFreq0 = 0;
}
brightness0 = map(adc0Reading, 0, 5000, 10, 254);
}
lightUpNet(4, -1, 1, brightness0, hueShift0);
int adc1Reading = 0;
int brightness1 = 0;
int hueShift1 = 0;
if (dacOn[1] == 1)
{
adc1Reading = dac1_8V.getInputCode();
int adc1Reading = 0;
int brightness1 = 0;
int hueShift1 = 0;
if (dacOn[1] == 1 && freq[1] < 17)
{
adc1Reading = readAdc(29, 1);
hueShift1 = map(adc1Reading, -2048, 2048, -50, 45);
adc1Reading = adc1Reading - 2048;
hueShift1 = map(adc1Reading, -2048, 2048, -50, 45);
adc1Reading = abs(adc1Reading);
brightness1 = map(adc1Reading, 0, 2050, 4, 100);
adc1Reading = abs(adc1Reading );
} else {
adc1Reading = amplitude[1];
}
brightness1 = map(adc1Reading, 0, 2050, 10, 254);
lightUpNet(5, -1, 1, brightness1, hueShift1);
showLEDsCore2 = 1;
firstCrossFreq1 = 1;
}
else
{
if (firstCrossFreq1 == 1)
{
lightUpNet(5);
showLEDsCore2 = 1;
firstCrossFreq1 = 0;
}
}
if (now - lastTime > 100000)
{
loopCounter++;
//
// int adc0Reading = analogRead(26);
// if (activeDac == 0)
// {
// for (int i = 0; i < (analogRead(27)/100); i++)
// {
// Serial.print('.');
//int adc0Reading = analogRead(26);
// if (activeDac == 0)
// {
// for (int i = 0; i < (analogRead(27)/100); i++)
// {
// Serial.print('.');
// }
// Serial.println(' ');
// }
// else if (activeDac == 1)
// {
// }
// Serial.println(' ');
// }
// else if (activeDac == 1)
// {
// for (int i = 0; i < (analogRead(29)/100); i++)
// {
// Serial.print('.');
// }
// Serial.println(' ');
// }
// for (int i = 0; i < (analogRead(29)/100); i++)
// {
// Serial.print('.');
// }
// Serial.println(' ');
// }
lastTime = now;
// Serial.println(count); // show # updates per 0.1 second
count = 0;
@ -429,7 +459,7 @@ int waveGen(void)
case '8':
if (activeDac == 0)
{
dac0_5V.setVoltage(0.0);
setDac0_5Vvoltage(0.0);
dacOn[0] = 0;
}
@ -440,16 +470,15 @@ int waveGen(void)
if (dacOn[1] == 0)
{
dac1_8V.setInputCode(offset[1] + calib[1]);
setDac1_8VinputCode(offset[1] + calib[1]);
}
break;
case '5':
if (activeDac == 1)
{
dac1_8V.setInputCode(offset[1] + calib[1]);
setDac1_8VinputCode(offset[1] + calib[1]);
dacOn[1] = 0;
}
if (activeDac != 3)
@ -458,7 +487,7 @@ int waveGen(void)
activeDac = 0;
if (dacOn[activeDac] == 0)
{
dac0_5V.setVoltage(0.0);
setDac0_5Vvoltage(0.0);
}
break;
case 'c':
@ -499,16 +528,16 @@ int waveGen(void)
mode[activeDac] = c;
break;
case '{':
case '{':
case 'f':
{
if (mode[0] != 'v')
{
dac0_5V.setVoltage(0.0);
setDac0_5Vvoltage(0.0);
}
if (mode[1] != 'v')
{
dac1_8V.setInputCode(offset[1]);
setDac1_8VinputCode(offset[1]);
}
return 0;
}
@ -517,19 +546,15 @@ int waveGen(void)
{
if (mode[0] != 'v')
{
dac0_5V.setVoltage(0.0);
setDac0_5Vvoltage(0.0);
}
if (mode[1] != 'v')
{
dac1_8V.setInputCode(offset[1]);
setDac1_8VinputCode(offset[1]);
}
return 1;
}
default:
break;
@ -590,54 +615,54 @@ int waveGen(void)
if (t < halvePeriod[activeDac])
{
if (activeDac == 0 && dacOn[activeDac] == 1)
dac0_5V.setInputCode(amplitude[activeDac]);
setDac0_5VinputCode(amplitude[activeDac]);
else if (activeDac == 1 && dacOn[activeDac] == 1)
dac1_8V.setInputCode(amplitude[activeDac]);
setDac1_8VinputCode(amplitude[activeDac]);
}
else
{
if (activeDac == 0 && dacOn[activeDac] == 1)
dac0_5V.setInputCode(0);
setDac0_5VinputCode(0);
else if (activeDac == 1 && dacOn[activeDac] == 1)
dac1_8V.setInputCode(offset[activeDac]);
setDac1_8VinputCode(offset[activeDac]);
}
break;
case 'w':
if (activeDac == 0 && dacOn[activeDac] == 1)
dac0_5V.setInputCode(t * amplitude[activeDac] / period[activeDac]);
setDac0_5VinputCode(t * amplitude[activeDac] / period[activeDac]);
else if (activeDac == 1 && dacOn[activeDac] == 1)
dac1_8V.setInputCode(t * amplitude[activeDac] / period[activeDac]);
setDac1_8VinputCode(t * amplitude[activeDac] / period[activeDac]);
break;
case 't':
if (activeDac == 0 && dacOn[activeDac] == 1)
{
if (t < halvePeriod[activeDac])
dac0_5V.setInputCode(((t * amplitude[activeDac]) / halvePeriod[activeDac]));
setDac0_5VinputCode(((t * amplitude[activeDac]) / halvePeriod[activeDac]));
else
dac0_5V.setInputCode((((period[activeDac] - t) * (amplitude[activeDac]) / halvePeriod[activeDac]) ));
setDac0_5VinputCode((((period[activeDac] - t) * (amplitude[activeDac]) / halvePeriod[activeDac])));
}
else if (activeDac == 1 && dacOn[activeDac] == 1)
{
if (t < halvePeriod[activeDac])
dac1_8V.setInputCode(t * amplitude[activeDac] / halvePeriod[activeDac]);
setDac1_8VinputCode(t * amplitude[activeDac] / halvePeriod[activeDac]);
else
dac1_8V.setInputCode((period[activeDac] - t) * amplitude[activeDac] / halvePeriod[activeDac]);
setDac1_8VinputCode((period[activeDac] - t) * amplitude[activeDac] / halvePeriod[activeDac]);
}
break;
case 'r':
if (activeDac == 0 && dacOn[activeDac] == 1)
dac0_5V.setInputCode(random(amplitude[activeDac]) );
setDac0_5VinputCode(random(amplitude[activeDac]));
else if (activeDac == 1 && dacOn[activeDac] == 1)
{
dac1_8V.setInputCode(random(amplitude[activeDac]) );
setDac1_8VinputCode(random(amplitude[activeDac]));
}
break;
case 'z': // zero
if (activeDac == 0)
dac0_5V.setVoltage(0);
setDac0_5Vvoltage(0);
else if (activeDac == 1)
dac1_8V.setInputCode(offset[activeDac]);
setDac1_8VinputCode(offset[activeDac]);
break;
case 'h': // high
Serial.println("\n\r\t\t\t\t waveGen\t\n\n\r\toptions\t\t\twaves\t\t\tadjust frequency\n\r");
@ -650,7 +675,7 @@ int waveGen(void)
mode[activeDac] = mode[2];
break;
case 'm': // mid
// dac1_8V.setInputCode(2047);
// setDac1_8VinputCode(2047);
break;
case 'a':
{
@ -903,14 +928,14 @@ int waveGen(void)
if (activeDac == 0 && mode[2] != 'v')
{
// freq[activeDac] = 0;
setDac0_5V(amplitude[activeDac] / 819);
setDac0_5Vvoltage(amplitude[activeDac] / 819);
mode[2] = 'v';
}
else if (activeDac == 1 && mode[2] != 'v')
{
// freq[activeDac] = 0;
// refillTable(0, offset[activeDac] + calib[1], 1);
setDac1_8V(((amplitude[activeDac] + calib[1]) / 276) - ((offset[activeDac] / 276) - 7));
setDac1_8Vvoltage(((amplitude[activeDac] + calib[1]) / 276) - ((offset[activeDac] / 276) - 7));
mode[2] = 'v';
}
else if (mode[2] == 'v')
@ -925,17 +950,74 @@ int waveGen(void)
case 's':
// reference
// float f = ((PI * 2) * t)/period;
// dac1_8V.setInputCode(2047 + 2047 * sin(f));
// setDac1_8VinputCode(2047 + 2047 * sin(f));
//
if (mode[activeDac] != 'v')
{
int idx = (360 * t) / period[activeDac];
if (activeDac == 0 && dacOn[activeDac] == 1)
dac0_5V.setInputCode(sine0[idx]); // lookuptable
setDac0_5VinputCode(sine0[idx]); // lookuptable
else if (activeDac == 1 && dacOn[activeDac] == 1)
dac1_8V.setInputCode(sine1[idx]); // lookuptable
setDac1_8VinputCode(sine1[idx]); // lookuptable
}
break;
}
}
}
void refillTable(int amplitude, int offset, int dac)
{
// int offsetCorr = 0;
if (dac == 0)
{
// offset = amplitude / 2;
}
for (int i = 0; i < 360; i++)
{
if (dac == 0)
{
sine0[i] = offset + round(amplitude / 2 * sin(i * PI / 180));
}
else if (dac == 1)
{
sine1[i] = offset + round((amplitude - (offset - 2047)) / 2 * sin(i * PI / 180));
}
else if (dac == 2)
{
sine0[i] = offset + round(amplitude / 2 * sin(i * PI / 180));
sine1[i] = offset + round(amplitude / 2 * sin(i * PI / 180));
}
}
}
void GetAdc29Status(int i)
{
gpio_function gpio29Function = gpio_get_function(29);
Serial.print("GPIO29 func: ");
Serial.println(gpio29Function);
bool pd = gpio_is_pulled_down(29);
Serial.print("GPIO29 pd: ");
Serial.println(pd);
bool h = gpio_is_input_hysteresis_enabled(29);
Serial.print("GPIO29 h: ");
Serial.println(h);
gpio_slew_rate slew = gpio_get_slew_rate(29);
Serial.print("GPIO29 slew: ");
Serial.println(slew);
gpio_drive_strength drive = gpio_get_drive_strength(29);
Serial.print("GPIO29 drive: ");
Serial.println(drive);
int irqmask = gpio_get_irq_event_mask(29);
Serial.print("GPIO29 irqmask: ");
Serial.println(irqmask);
bool out = gpio_is_dir_out(29);
Serial.print("GPIO29 out: ");
Serial.println(out);
Serial.printf("(%i) GPIO29 func: %i, pd: %i, h: %i, slew: %i, drive: %i, irqmask: %i, out: %i\n", i, gpio29Function, pd, h, slew, drive, irqmask, out);
}

View File

@ -16,13 +16,15 @@ void dacSine (int resolution = 9);
void dacTriangle (void);
void setDac0_5V(float value);
void setDac1_8V(float value);
void setDac0_5Vvoltage(float value);
void setDac1_8Vvoltage(float value);
void setDac0_5VinputCode(uint16_t value);
void setDac1_8VinputCode(uint16_t value);
void refillTable (int amplitude = 2047, int offset = 2047, int adc = 2);
int waveGen(void);
void GetAdc29Status(int i);
float readAdc(int channel, int samples = 10);
int readAdc(int channel, int samples = 10);

View File

@ -57,7 +57,8 @@ void setup()
#ifdef FSSTUFF
LittleFS.begin();
#endif
setDac0_5V(0.0);
setDac0_5Vvoltage(0.0);
setDac1_8Vvoltage(1.9);
}
void setup1()
@ -74,6 +75,7 @@ void setup1()
startupColors();
lightUpRail();
showLEDsCore2 = 1;
}
@ -346,6 +348,11 @@ void loop1() // core 2 handles the LEDs and the CH446Q
lightUpRail();
}
if (rails > 3)
{
Serial.print("\n\r");
Serial.print(rails);
}
delayMicroseconds(5200);