I have made several posts on topics relating to my project. I am essentially working on a BLDC motor controller that I designed and built. This particular part pertains to measuring the current through the motor via a current sense resistor, a MAX40201 current sense amplifier and a Teeny 3.6.
To do this, I had to adjust the registers on the Teensy 3.6 to have the PWM trigger a PDB timer, which in turn activates the ADC at a specific interval so that current measurments are taken ONLY while the MOSFETs are "active", otherwise it will just measure zero amperes due to the MOSFETS isolating the current sense resistor from the motor.
This is where it gets tricky and I could use some help. Paul's stock analogRead() stuff, housed in analog.c, overwrites ALL the ADC registers that I set, disabling the ADC interrupt registers that I need, as soon as an
is called, whether or not I am reading the current sense pin or some other pin.
How can I maintain the settings that I set for measuring current while still allowing the use of analogRead() without creating a custom version of the analogRead() functions? Is there some simple way to backup and restore the registers after a call to analogRead()?
------------------------------------
Separate, but related question:
I noticed that Paul's analog.c code lumps the setting for ADC0 and ADC1 together. That is if you set ADC0 to 16bit, then ADC1 gets set to 16 bit also. Does the K66 controller require it to be that way? Can ADC0 and ADC1 have separate settings such that one reads 16 bit while the other reads 12 bit, for example?
To do this, I had to adjust the registers on the Teensy 3.6 to have the PWM trigger a PDB timer, which in turn activates the ADC at a specific interval so that current measurments are taken ONLY while the MOSFETs are "active", otherwise it will just measure zero amperes due to the MOSFETS isolating the current sense resistor from the motor.
This is where it gets tricky and I could use some help. Paul's stock analogRead() stuff, housed in analog.c, overwrites ALL the ADC registers that I set, disabling the ADC interrupt registers that I need, as soon as an
Code:
analogRead()
How can I maintain the settings that I set for measuring current while still allowing the use of analogRead() without creating a custom version of the analogRead() functions? Is there some simple way to backup and restore the registers after a call to analogRead()?
------------------------------------
Separate, but related question:
I noticed that Paul's analog.c code lumps the setting for ADC0 and ADC1 together. That is if you set ADC0 to 16bit, then ADC1 gets set to 16 bit also. Does the K66 controller require it to be that way? Can ADC0 and ADC1 have separate settings such that one reads 16 bit while the other reads 12 bit, for example?
Last edited: