0

Trinket 5V reading off of a 3V Feather?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trinket 5V reading off of a 3V Feather?

by jonathanyhsu on Mon Jun 11, 2018 7:22 pm

I was attempting to create an external watchdog using a Trinket 5V (https://www.adafruit.com/product/1501) that could monitor a pin state on a 3.3V AdaFruit Feather M0 RFM69HCW (https://www.adafruit.com/product/3176). I was able to Serial.println() that my M0 was executing digitalWrite() on the pin, toggling it between HIGH and LOW. However, my Trinket 5V cannot seem to digitalRead() either of these. I was wondering if perhaps this is due to the voltage differences between the 3.3V and 5V logic devices, and if so, whether it's possible to have the 5V Trinket digitalRead() off the 3.3V M0.

Oddly enough, because my 5V Trinket cannot seem to read the pin state changes, it executes the code block to digitalWrite(RESET_PIN, LOW) which is connected to the RST pin on the 3.3V M0. This appears to work, as my M0 then enters a regular restart loop based upon the duration constants in my code.

I'm not sure if I'm missing something in how I should setup and use the pin I/O function calls, or if I need to move to a 3.3V Trinket to watch over the 3.3V M0. Any ideas for further debugging or advice on implementation would be appreciated.

-Jonathan


M0 code snippet (main device):
Code: Select all | TOGGLE FULL SIZE
#define HEART_BEAT_PIN   15
int heart_beat = HIGH;
unsigned long heart_beat_timer_dur = 1000;
unsigned long heart_beat_start_time;

void setup() {
  heart_beat_start_time = millis();
}

void loop() {
if (millis() - heart_beat_start_time >= heart_beat_timer_dur) {
    int new_state;
    if (heart_beat == HIGH) {
      new_state = LOW;
    } else {
      new_state = HIGH;
    }
    digitalWrite(HEART_BEAT_PIN, new_state);
    heart_beat = new_state;
    heart_beat_start_time = millis();
    sprintf(sprintf_buf, "WATCH : Setting heart beat pin %d to %d", HEART_BEAT_PIN, new_state);
    Serial.println(sprintf_buf);
  }
}


5V Trinket code snippet (external watchdog device):
Code: Select all | TOGGLE FULL SIZE
#define HEART_BEAT_PIN    4
#define LED_PIN      1
int cur_state;

void loop() {
  cur_state = digitalRead(HEART_BEAT_PIN);
  digitalWrite(LED_PIN, cur_state);
}

jonathanyhsu
 
Posts: 25
Joined: Wed Jun 15, 2016 8:34 pm

Re: Trinket 5V reading off of a 3V Feather?

by adafruit_support_bill on Mon Jun 11, 2018 7:32 pm

In general the 5v AVR processors will recognize a 3.3v logic HIGH signal. Do you have a common ground connection for a signal reference?

adafruit_support_bill
 
Posts: 70378
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V reading off of a 3V Feather?

by jonathanyhsu on Tue Jun 12, 2018 12:05 am

I thought I had a common ground by having a 22 AWG wire connect the GND header on the M0 with the GND on the Trinket, but I still can't seem to digitalRead() the designated pin. One thought is I wanted to verify that pin 15 on the M0 is acceptable for this use; my reading of the pinouts doesn't seem to indicate otherwise, but I could be wrong. The other thing I need to try is soldering in some headers onto my Trinket 5V and see if better connections solves the issue.

-Jonathan

jonathanyhsu
 
Posts: 25
Joined: Wed Jun 15, 2016 8:34 pm

Re: Trinket 5V reading off of a 3V Feather?

by adafruit_support_bill on Tue Jun 12, 2018 5:59 am

Pin 15 (A1) should be fine. But you need to declare it as an output pin. I believe on the M0, the GPIO pins default to input.
https://www.arduino.cc/reference/en/lan ... o/pinmode/

adafruit_support_bill
 
Posts: 70378
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V reading off of a 3V Feather?

by jonathanyhsu on Tue Jun 12, 2018 4:41 pm

I believe that pinMode(..., OUTPUT) solved my issue, I now have the basic functionality of the watchdog working (i.e. the watchdog LED blinks as it reads the pin on the monitored device, and it does reset the monitored device should there be a missing heartbeat).

I am currently using two LiPoly batteries, one each for the Feather M0 and then the Trinket 5V. Ideally, I'd like there to only be one battery and have the watchdog device draw its power from the same bus (or battery) as the monitored device. I could buy a Trinket 3V in order to use the 3V pin on the monitored device. My only question is, the whole reason I'm building a watchdog is because there is a good chance of electrical interference (voltage drop/fluctuation?) causing a device lockup. Would such an issue affect the Trinket if it gets power into the BAT pin? My understanding is the BAT pin leads into a regulator of some kind, which may protect it from whatever is locking up the monitored device.

If not, are there any AdaFruit breakout boards which can provide such functionality (or add a small coin battery backup)? My search yielded no results, but perhaps I am searching for the wrong terms.

Thanks,
-Jonathan

jonathanyhsu
 
Posts: 25
Joined: Wed Jun 15, 2016 8:34 pm

Re: Trinket 5V reading off of a 3V Feather?

by adafruit_support_bill on Tue Jun 12, 2018 5:34 pm

The Trinket has a voltage regulator - much like the one on the M0. It does provide some measure of isolation. But if the primary supply voltage drops to a level approaching the regulated output voltage, the regulation will fail and the output will be unstable. If both processors share the same primary power source, they will likely react similarly to a glitch on that source.

You can add additional bypass capacitance between VCC and GND after the regulator to help smooth over momentary dropouts.

That said, battery output tends to be pretty stable. If you are seeing processor freezes, then the cause is not likely due to battery fluctuations.

adafruit_support_bill
 
Posts: 70378
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V reading off of a 3V Feather?

by jonathanyhsu on Tue Jun 12, 2018 5:45 pm

Thanks for the information; to clarify, my power issues do not stem from my LiPoly battery but rather the electrical device my Feather M0 is trying to control via a relay. What I've found out is that the machinery my Feather M0 is controlling has its own relays (without diodes) and when the relay is closed, I'm getting reverse voltage from all the charge leaving the inductive coil. My experiments have led me to believe that the charge is building up and arcing cross the contacts in my own AdaFruit Feather relay. I've modified the machinery and added some Schotky diodes, but I still occasionally seem to get an arc(?) event, which can cause my M0 to lock up (or reboot) unless it is power cycled.

If I understand your comments correctly, there is really no expectation that the regulator on the watchdog Trinket would do any better than the regulator on the Feather M0?

Thanks,
-Jonathan

jonathanyhsu
 
Posts: 25
Joined: Wed Jun 15, 2016 8:34 pm

Re: Trinket 5V reading off of a 3V Feather?

by adafruit_support_bill on Tue Jun 12, 2018 6:49 pm

It could be inductive flyback from the relay(s). It could also be EMI from the equipment (motors maybe?) that are being controlled. Even if there is no direct electrical connection, that kind of noise may be coupling inductively back into your Feather. It may or may not be via the power & ground wires. It could also be coupling in through the signal wire from your GPIO pin.

There are few things you can do to address that:

* Keep the wiring as separate as possible between the control side and the machinery under control. If wires must cross, have them cross at right angles if possible.

* Shielding and/or twisted pair wiring can reduce radiated EMI from machinery wiring. It can also reduce noise pickup on the control side.

* Ferrite chokes on the relay wiring can help tame spikes as well.

adafruit_support_bill
 
Posts: 70378
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V reading off of a 3V Feather?

by jonathanyhsu on Tue Jun 12, 2018 9:30 pm

I did a test, and it looks like I'm arcing inside the AdaFruit relay contacts when the other relay it controls shuts down. That spark over the contacts in my AdaFruit relay seems to be causing my reboots, and occasionally a lock up.The reason I believe that is if I swap out the 2nd relay with another that has diodes, the problem is almost mitigated completely. I don't think it's EMI because this occurs regardless of distance from the machinery (I can do a few feet to around 12 feet away).

Are there any breakout boards that can provide power to a Trinket, but also provide some measure of additional protection against the power fluctuations going on in the monitored device?

Thanks,
-Jonathan

jonathanyhsu
 
Posts: 25
Joined: Wed Jun 15, 2016 8:34 pm

Re: Trinket 5V reading off of a 3V Feather?

by adafruit_support_bill on Wed Jun 13, 2018 6:13 am

I don't think it's EMI because this occurs regardless of distance from the machinery (I can do a few feet to around 12 feet away).

What you are describing is the definition of EMI - and it is in close proximity to the Feather. There is no electrical contact between the coil side of the relay and the contact side. If you are seeing arcs in the relay contacts, you are also going to get EMI radiating from the wires that are carrying the current that generates that spike.

The reason I believe that is if I swap out the 2nd relay with another that has diodes, the problem is almost mitigated completely.

Sounds like a solution to me. Anywhere you have a relay, you should have flyback diodes to suppress the inductive spike. - at the source.

Are there any breakout boards that can provide power to a Trinket, but also provide some measure of additional protection against the power fluctuations going on in the monitored device?

You can add all sorts of power supply filtering and bypass capacitance. But that may not help if the EMI is coupling in via a different path. That is why it is best to suppress EMI at the source.

adafruit_support_bill
 
Posts: 70378
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V reading off of a 3V Feather?

by jonathanyhsu on Wed Jun 13, 2018 1:10 pm

Thanks for the clarification on EMI, Bill. One further question I have is about stopping the inductive spike at its source. I have tested relays with diodes, as well as alligator clipping on a Schotky diode, but it doesn't seem to eliminate the problem completely. Normally I would get a reboot, with the occasional lockup completely until power is cycled. With the diodes, I still reboot perhaps 50% of the time, and the lockups are now about 1 in 20. Aside from the built-in diodes and the Schotky diodes, are there any other things I can try? My ability to modify the machinery is somewhat limited by my unfamiliarity with their wiring and my own ignorance. I understand this may be an out of bounds question since it's not related to an AdaFruit product.

Thanks,
-Jonathan

jonathanyhsu
 
Posts: 25
Joined: Wed Jun 15, 2016 8:34 pm

Re: Trinket 5V reading off of a 3V Feather?

by adafruit_support_bill on Wed Jun 13, 2018 1:29 pm

A diagram of the system would be helpful. As I understand it, you have the Feather relay driving another relay that is switching power to the equipment?

The Feather relay has a built-in diode to protect the Feather from the kickback of that coil. You would need another one on the coil of the equipment relay to protect the Feather and its relay. The diode should be rated to handle at least as much current as the coil draws when energized - since that will be the current level of the reverse spike when de-energized. All else being equal, Schottky diodes tend to be faster, so provide more protection. There are also diodes that are specifically designed for flyback protection.

Aside from the remedies mentioned above, if you have access to a digital oscilloscope, you can probe various parts of the system and record the fluctuations. This can help you to understand the nature of the interference and how it is coupling into your system.

adafruit_support_bill
 
Posts: 70378
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V reading off of a 3V Feather?

by jonathanyhsu on Wed Jun 13, 2018 3:05 pm

Correct, I apologize for not including more background info. I previously inquired about this issue before, on this thread: viewtopic.php?f=57&t=130848&p=652464#p652464 and I have been experimenting with the diodes and relays. My current status is it doesn't seem to completely reduce the issue (i.e. I still get reboots from arcing, with the occasional lockup), and I'm shooting for higher reliability. One thought is the Atlas trap machines are driven by 12V car or marine batteries, is this excessive for the diode(s) to dissipate? In my experiments, I've been trying out a 1N5822 Schottky diode from Amazon, although it's quality is unknown. I speculate as such only because testing on my bench with smaller 6V or 9V batteries doesn't yield any issues, but testing in the field with actual 12V car batteries still exhibits the problem.

This picture illustrates a simple demo of the problem; my Feather relay completes a circuit that provides power to another relay that switches power to the DC motor on the equipment (in this case, an Atlas trap machine, not pictured).
IMG_0054.jpg
IMG_0054.jpg (485.67 KiB) Viewed 119 times

My attempt at using the Trinket as an external hardware watchdog is based upon my inability to yet solve the issue at the source.

Thanks,
-Jonathan

jonathanyhsu
 
Posts: 25
Joined: Wed Jun 15, 2016 8:34 pm

Re: Trinket 5V reading off of a 3V Feather?

by adafruit_support_bill on Wed Jun 13, 2018 4:08 pm

One thought is the Atlas trap machines are driven by 12V car or marine batteries, is this excessive for the diode(s) to dissipate? In my experiments, I've been trying out a 1N5822 Schottky diode from Amazon, although it's quality is unknown. I speculate as such only because testing on my bench with smaller 6V or 9V batteries doesn't yield any issues, but testing in the field with actual 12V car batteries still exhibits the problem..

Higher voltage means proportionally higher current and a proportionally higher spike. To select an appropriate diode you need to know the current draw of your automotive relay. Make sure that your diode current rating is at least as high as the current draw for the coil of the relay at 12v.

This picture illustrates a simple demo of the problem; my Feather relay completes a circuit that provides power to another relay that switches power to the DC motor on the equipment (in this case, an Atlas trap machine, not pictured).

Do you power the trap machine from the same battery as the relay? That provides a path for the EMI from the machine itself back to your Feather.

Also, your wires as shown make ideal antennae for broadcasting EMI to nearby components. Twisted-pair and/or shielded wiring can help limit that. https://en.wikipedia.org/wiki/Twisted_pair

adafruit_support_bill
 
Posts: 70378
Joined: Sat Feb 07, 2009 10:11 am

Re: Trinket 5V reading off of a 3V Feather?

by jonathanyhsu on Wed Jun 13, 2018 10:54 pm

Thanks Bill, to answer your question, the Atlas trap machine (which is composed of a DC motor, a Bosch relay, and additional switches and wiring) is powered off a 12V car/marine battery. My Feather M0 RFM69HCW + Feather relay box is powered off its own 2500mAh LiPoly battery. My Feather
I spoke with the manufacturer and they said their on/off switches are based upon connecting the ground hub, and not the hot, although I don't know if that's relevant to my case.

As soon as my Feather relay breaks the circuit and goes back to its unpowered state, the whole Feather M0 reboots. I believe this is caused by arcing between the Feather relay contacts, because it only happens at the same time as the Feather relay breaking the circuit (I can manipulate the time the Feather relay completes the circuit, and it always happens at the end). So the theory is the Bosch relay's inductive coil is not dissipating the current fast enough before it builds up at the contacts, and then arcs across them in the Feather relay.

The relay in question is a Bosch 0 332, 209 158, from this catalog http://www.bosch-ibusiness.com/download ... _73801.pdf

Below is the catalog page of the relay with diode that I have installed. It shows the current (rating?) as 30A/20A for the NO and NC paths (not sure on the terminology here). Since it's an automotive relay, I would expect it to be able to handle the draw from a 12V car battery.
Screen Shot 2018-06-13 at 7.25.15 PM.png
Screen Shot 2018-06-13 at 7.25.15 PM.png (128 KiB) Viewed 99 times


I did try building shielded cables and twisted pair cables (of varying lengths from 3 to 6 feet) but that didn't seem to resolve the issue either (unless I should be using twisted pair cables in conjunction with the diodes or something).

Thanks,
-Jonathan

jonathanyhsu
 
Posts: 25
Joined: Wed Jun 15, 2016 8:34 pm

Please be positive and constructive with your questions and comments.