MisterBill
New member
Hello. I just started using Teensy a few days ago to allow me to use the FreqMeasure library to check the clock frequency of a processor on a board under test. The main brain in the fixture is an Arduino Mega 2560 v3, but a) I'm already using every single pin it has, and b) it's not fast enough to measure the frequency (16Khz or 32Khz, depending on the mode) and still get everything else done. I got FreqMeasure and I2C communication between the Mega and the Teensy working pretty easily. But then I realized I needed to measure a 3.3V and -3.3V supply, and thought, "Hey - I can just use the analog inputs on the Teensy and request the values via I2C like I'm doing with the frequency!". But for some reason, while the 3.3v reads fine on A7, I'm getting 0.00 on A8, which is connected to the output of a unity gain inverting LM324 that gives me 2.96V on a meter when fed -2.96V. I've tried swapping pins around, inserting delays, etc, but nothing works. Any suggestions? I realize I need to add some code to reply to requests for the voltage, etc, but I need to *get* it first! Any help would be appreciated. Impendance issue, maybe?
-Bill
-Bill
Code:
#include <Wire.h>
#include <FreqMeasure.h>
byte SlaveReceived = 0;
int frequency;
double sum = 0;
int count = 0;
int maxWait = 10000; //max # of ms to wait for a reading before returning 0
float v33; //+3.3v from CBA
float n33; //-3.3v from CBA
void setup() {
//Serial.begin(57600);
Wire.begin(8);
FreqMeasure.begin();
//Wire.onReceive(receiveEvent); //Function call when Slave receives value from master
Wire.onRequest(requestEvent); //Function call when Master request value from Slave
}
void loop() {
v33 =(analogRead(A8) / 1023 * 3.3);
//delay(500);
n33 = (analogRead(A9) / 1023 * 3.3); //-3.3v inverted via LM324 to +3.3v
//delay(500);
Serial.println("v33=" + String(v33));
Serial.println("n33=" + String(n33));
if (FreqMeasure.available()) {
// average several readings together
sum = sum + FreqMeasure.read();
count = count + 1;
if (count > 30) {
frequency = FreqMeasure.countToFrequency(sum / count);
Serial.println("[" + String(frequency) + "]");
sum = 0;
count = 0;
}
}
}
void requestEvent(void) //called when master wants value from slave
{
// int start = millis();
// frequency = 0;
// do {
//
// }
//} while ((frequency == 0) && (millis() < (start + maxWait)));
byte msb = highByte(frequency);
byte lsb = lowByte(frequency);
// Serial.print("[" + String(frequency) + "]");
// Serial.println("Sending: " + String(msb) + " " + String(lsb));
Wire.write(msb); // sends one byte
Wire.write(lsb);
}