nerdyscout / Arduino_MCP3x6x_Library

Library to support Microchip MPC3x6x 16/24bit analog to digital converters.
https://nerdyscout.github.io/Arduino_MCP3x6x_Library
MIT License
18 stars 9 forks source link

mcp 3462 with Arduino Zero definition-question not issue! #16

Open beyondblood opened 5 months ago

beyondblood commented 5 months ago

Not really an issue, more of a question so apologies...

I'm attempting to read from channel 0 in mux mode but having issues even entering the setup and loop sections. I'm assuming it's something to do with my mcp definition since I've tested the println function and it seems to work. I'm using an Arduino Zero which is SAMD21. I added a lot of print statements to try and figure out where the program is/isn't making it to. If I go by these statements, the setup and loop aren't being read. Assuming that I've done something really dumb since I'm quite new to this.

MCP3462 mcp(10); //the problem?

void setup() { Serial.begin(115200); while (!Serial) ; Serial.println(FILE); if (!mcp.begin()) { Serial.println("failed to initialize MCP"); while (1) ; } }

// the loop routine runs over and over again forever: void loop() { // read the input on default analog channel: int32_t adcdata = mcp.analogRead(MCP_CH0);

// Convert the analog reading double voltage = adcdata * mcp.getReference() / mcp.getMaxValue(); Serial.println("converted voltage");

// print out the value you read: Serial.println("voltage: "); Serial.print(voltage, 10); Serial.println("printed voltage");

// pause program for one second delay(1000); }

nerdyscout commented 5 months ago

do you use a pullup resistor at pin /IRQ ?

beyondblood commented 5 months ago

Yes, I've got a pullup at IRQ going to 3.3V. I was thinking maybe my problem was with settings as I have the master clock floating as I wanted to use the internal clock. Attached is pic of my hardware config. Thanks again!

MCP3462_Schematic

nerdyscout commented 5 months ago

he pull-up value can be equal to 100-200k for a weak pull-up using the typical clock frequency datasheet, page 31

beside that I am relatively sure your problem is because of my code... sorry. which exact commit are you on?

does your code still freeze if you remove int32_t adcdata = mcp.analogRead(MCP_CH0); ??

if so: there is a while loop inside which is not working, I have seen other people fail here

    while (!_status.dr) {
      _status = read(&adcdata);
    }

please read https://github.com/nerdyscout/Arduino_MCP3x6x_Library/pull/5#issuecomment-1906607357 there this issue was already discussed.

beyondblood commented 5 months ago

Hi and thanks for responding! I've changed out my resistor for a 100k, so thank you for that catch. When I comment out int32_t adcdata = mcp.analogRead(MCP_CH0); the loop starts printing/working again, which is strange. I'm new to all this so I've downloaded the files from the 'examples' section and the main files, not sure which commit. I'm thinking it's something to do with my definition MCP3462 mcp(10);

nerdyscout commented 5 months ago

as just proven the definition of mcp() is fine, problem is the readAnalog() function. I am sorry but I can not give any further support.

beyondblood commented 5 months ago

no worries! Thank you for your time!