Arduino Giga current to voltage amplifier

I'm trying to build a light detection circuit with an arduino giga by using a photo diode as a current generator. I'm essentially trying to build the circuit shown below but using the onboard op amp of the arduino giga. I've found the STMSpeeduino library which allows you to set up the amplifier as a non-inverting opamp but it doesn't have inverting opamp capabilities. Is there a way to easily access the inverting opamp, and will this work for my circuit?

TransImpedance Amp

Hey, STMspeeduino creator here, apologies I only noticed your message now, I believe this would be simple to do, might only need to change one register value, so if it would by any chance still be useful, I can have a look into it.

1 Like

Hey, I tried to slightly alter the code, for pins it would be A0 out

A0 out
A1 in negative
A2 in positive

and here's the updated Opamp.cpp code, lmk if it works

#include "Opamp.h"

#if defined(ARDUINO_PORTENTA_H7_M7)
#pragma message "There are no OPAMP pins abailable on the portenta"
#endif

void OPAMPCFG(int Gain) {

  // SET_BIT(RCC->AHB4ENR, RCC_AHB4ENR_GPIOAEN | RCC_AHB4ENR_GPIOBEN | RCC_AHB4ENR_GPIOCEN);

  SET_BIT(RCC->APB1HENR, RCC_APB1HENR_OPAMPEN);                                                                             //Enable power for the Opamp
  OPAMP1->CSR = 0;                                                                                                          //Set up opamp 1
  SET_BIT(OPAMP1->CSR, OPAMP_CSR_CALSEL_1 | OPAMP_CSR_OPAHSM | OPAMP_CSR_OPAMPxEN | OPAMP_CSR_VMSEL_1 | OPAMP_CSR_CALOUT | OPAMP_CSR_PGGAIN_3);  //Setup OPAMP1 further
  //Set Gain
    //Callout
  if (Gain == 16) {
    SET_BIT(OPAMP1->CSR, OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1);
  } else if (Gain == 8) {
    SET_BIT(OPAMP1->CSR, OPAMP_CSR_PGGAIN_1);
  } else if (Gain == 4) {
    SET_BIT(OPAMP1->CSR, OPAMP_CSR_PGGAIN_0);
  };
    
    
    

}