Project

General

Profile

Can the digital I/O pins on the RFM69CW be used to control other logic lines?

Added by sanb 9 months ago

Hi,

I am using a RFM69CW radio connected to an ATTiny84 MCU. On the MCU, 4 of the digital I/O pins are connected to the RFM69CW as below:

       ATT84           RFM69CW
         D1              NSS
         D2              DI00
      MOSI, D4           MISO
      MISO, D5           MOSI
      SCK, D6            SCK

All other available i/o points on the MCU are also used in the rest of circuit on the node. And I now need one more digital pin which I can program. This one will be used to drive a logic line (on a high-current driver carrier board) to HIGH (3.3V logic) for 10-15ms and most of the time it will be LOW. When HIGH, and if I am reading the driver (DRV8833, DRV8838) data sheet correctly, it will draw current in the 10s of microAmp range.

RFM69CW has i/o pins, only one of which (DIO0) is used to communicate with the MCU. Since I am out of i/o pins on the MCU, I am wondering if I can use on the remaining digital i/o pins on the RFM69CW? If so, how? Is there are down side of using them?


Replies (12)

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by JohnO 9 months ago

I wonder if you could use the RFM69CW clock output pin - it would be a square wave which you might needs to sort out somehow.

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by martynj 9 months ago

sanb,

Could you provide more details of the load on the driver board? Are you using this just as a buffer for an occasional pulse output? Is the timing (initiation and duration) critical?

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by sanb 9 months ago

Thanks for your responses and time, JohnO, martynj

Quick answers to martynj questions first:

  1. The driver board is being used to provide an occasional pulse of at least 10ms duration to control DC-latching solenoids. Since the pulse will draw up to 2A (for ~10ms) and its polarity needs to be controlled, it needs a separate power source and an H-bridge driver (see below).

  2. The duration of the pulse has to be at least 10ms (can be longer, but preferably not by much since it drains the 9V battery which supplies the power for this pulse). The duration, as long as it is longer than 10ms is not too critical.

  3. The initiation time can also be approximate. I.e., it's not critical - accuracy of order (many) seconds is OK (this is typically the time of the day when the sprinklers are started/stopped). Note that this load is not for the DIO lines. DIO lines use 3.3V logic and draws, I think, 10-30 microAmps.

Following are some more details of what I am trying to do. The project is to make a sprinkler controller which can be commanded over-the-air via an RFM69CW on the remote node.

The node has a ATTiny84 (ATT84) which controls the RFM69 and a driver for the sprinkler DC-latching solenoids. The ATT84 and RFM69 are powered from 2xAA batteries.

The solenoid driver has 3.3V logic circuit which is also powered by the same 2xAA batteries. I am experimenting with two driver boards based on DRV8833 (dual driver https://www.pololu.com/product/2130) and DRV8838 (single driver https://www.pololu.com/product/2990) H-bridge
chips.

They are similar for the purpose of our current discussion. I will describe use of DRV8838 board. On this board, the power for the solenoids is via separate 9V battery (I am using 6xAA batteries). To trigger a solenoid requires a 6-12V pulse of at least 10ms duration (I have tested that 10ms duration is sufficient). The solenoid coil is a 3ohm load. The pulse therefore draws up to 2-3A max. (much less on an average) current from the 9V source. Since the pulse is issued infrequently (few times a week) a 9V battery is practically usable for reasonable length of time (tests suggest ~1 year). The polarity of this pulse determines whether the solenoid is "opened" or "closed" (hence the need for the H-bridge). The polarity is controlled by two logic lines on the driver carrier board (HIGH-LOW vs LOW-HIGH). Lets call them IN1 and IN2.

These boards also have an nSLEEP logic line. nSLEEP=LOW puts all the circuits on the board to sleep and in this state it drains a fraction of a microAmp (as against milliAmps when active). It is therefore critical to extract reasonable battery life. It is for this nSLEEP line that I need another digital I/O pin (my final goal is to control 5 solenoids, which uses 6 digital I/O pins on the ATT84, leaving no pin available for the nSLEEP control. Only one solenoid will be triggered at a time).

The steps that controller will go through for activating the valve therefore are:

  1. RFM69CW sends a ping to the base station (wall-socket powered) every minute, and waits, for a few seconds max. (in practice only for O(ms)), to receive a packet from the base station.

  2. The base station responds with a command. If the command is a NOOP, the remote RFM69 and ATT84 goes to sleep immediately. If the command is to, say, open the solenoid:

    • raise nSLEEP to HIGH (wake up the driver)
    • wait for some time to let the circuit stabilize
    • set the IN1 to HIGH and IN2 to LOW. This starts the pulse.
    • wait for 10ms
    • set both IN1 and IN2 to LOW (shutting off the power to the solenoid)
    • set nSLEEP to LOW (put the drive back to sleep)
    • set RFM69 and ATT84 to sleep

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by martynj 9 months ago

sanb,

I suggest re-allocating pins/functions a little. Drive nSLEEP from the RFM69CW - the timing constraints are loose and the sequence of radio listen/possible solenoid change seems a good fit.

Expanding on JohnO's idea, with the schematic below, a clock signal on DIO5 is charge pumped into the small cap. Enabling the clock on the lowest setting (1Mhz) charges the cap rapidly, enough to lift nSLEEP above the trigger point (this input is luckily defined with a Schmitt threshold). Turning off the clock reverses the effect, but much slower (about 0.5ms with the C value shown). I'm assuming the Vcc rail is 3.3v
The clock signal can be enabled in any radio mode apart from sleep by setting the right bits in RegDioMapping2 (0x26) - 0x05 enable, 0x07 disable
Control registers are mostly preserved during sleep, so best to disable the clock signal before sleeping the radio to prevent an unexpected DRV8833/38 enable on wakeup.
Note that at POR, the clock signal is enabled until the RFM library init() is run.
This method costs a couple of generic parts + you need SPI bus transactions to enable/disable - use the library for this when back in idle mode to avoid any clashes with other radio SPI activity (there is no transaction level protection in the driver).

If needed a further independent output signal can be created, but it will take more glue logic and playing some games with the SPI driver to do this.

Clock_makes_enable.png (80 KB) Clock_makes_enable.png Making an enable from the radio clock output
2728

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by sanb 9 months ago

Thanks @martynj. I will certainly try this out and report back here with what I find. Thanks for the schematic also. I wouldn't have thought of the diode in there (that's to prevent any current flowing back to the radio?).

Is my understanding correct that I can enable/disable the clock signal from the code running on ATT84. I.e. I will enable the clock signal only when there is a command that would use DRV8833/38 and not otherwise. To put it another way, the clock signal won't be enabled every time the radio wakes up (which will happen once every minute).

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by martynj 9 months ago

sanb,

The diode forms a charge pump into the cap to make a steady logic level from the unsuitable pulsating clock signal.
You can control the clock signal (and hence the DRV8833/38 enable/disable) at will, provided you follow the guidelines mentioned to avoid confusing the library SPI traffic to and from MCU to RF module.
This should fit nicely into your flow - the radio will be out of sleep mode to collect the control packet from central, which is either a do nothing or change a solenoid state. Then disable the clock if used, before sleeping the radio module.

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by sanb 8 months ago

martynj

Apologies for the silence on this. I haven't been able to get to testing your idea yet - partly because I have been dealing with other issues in the driver part of the circuit which cropped up over time that I did not anticipate (namely, continuous drain of the power source (6xAA batteries) for the solenoid).

Here is brief description of the problem (I can give more details if needed): In the attached diagram, I am using A4988 as a proxy for the actual H-bridge driver I am using (DRV8838) since I could not find a Fritzing part for it.

I have been trying to solve the problem of switching on/off the power (from 9V source) to the large capacitor (3300uF) in parallel using a n-channel MOSFET switch. This 9V is the power source for the solenoid via the DRV8838 driver. The gate of the MOSFET is controlled by a digital line from the ATT84 (PIN12). If I don't switch off the 9V supply to the cap, it drains the battery on few weeks timescale. This switch works fine, but if I connect any of the control lines from the ATT84 to the DRV, for some reason the cap begins to draw power from the 9V source. If I don't connect the control lines (PINS 10, 11) from ATT84 to the DRV, all is well with the switching of the 9V power to the cap and the DRV (but without the control lines, it's useless of course).

I am currently using three 3.3Kohm resistors in my test circuit only as a quick-n-dirty replacement for a 9V to 3V converter. The VMOT of the driver gets the power source for the solenoid. The 1A and 1B pins of the driver is where the solenoid will be connected. EN and DIR pins control the polarity of the 1A, 1B pins. If I disconnect wires from PIN 10,11, the circuit works as desired (the 9V power to the cap and the driver is on only when PIN 12 is HIGH). If I connect PIN 10 or 11, voltage across the cap is about 5V and it's coming from the 9V source, even when PIN 12 is LOW.

My diagnosis of the problem: when PIN 12 is LOW, the ground of driver chip is floating and in this state, there seems to be a path inside the driver to the GND. Also, when PIN 10/11 of ATT84 are LOW, they are probably connected to the GND on it. If these two statements are indeed correct, then via the driver, the drain of the MOSFET has a path to the GND of the 9V source, completing the circuit for the cap and VMOT pin of the driver.

If so, I don't really know how to, even conceptually, solve the problem. Any suggestions would be most helpful.

Ultimately, the goal is connect the RFM69CW radio to ATT84 and control multiple solenoids via the radio link.

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by martynj 7 months ago

sanb,

There are some problems with your schematic as drawn:

  • The GND pin on the DRV8838 does not appear to actually have a ground connection.

  • From the chip schematic, you don't supply 3v to the driver chip - it generates its own internal supply; that pin is just for an external decoupling capacitor.

  • Yes, large value electrolytics are quite leaky especially as they age. You can minimize this by reducing the value of the capacitor - you only need enough charge to feed the few milliseconds of actuation, any extra is wasted since it will leak away over time. There is a complication here also that breaking the current you have just established in the actuator coil will create a reverse spike that has to go somewhere. Do the actuators have built in diode protection for this or the Pololu board has these built in?

The alternative is along the lines you have tried but you need a high-side switch - this needs a PFET not an NFET.

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by sanb 7 months ago

martynj,

Thanks very much for your time for this. I am attaching a modified circuit that I have recently tested. It seems to work fine now, though I haven't connected it to the solenoid yet (so don't know if something that I can see right now will obviously fail when the DRV output has a high load. The solenoid coil is rated at just 3ohm). If something is clear to you that will fail when I do connect it to the solenoid (perhaps late next week), I will be very grateful if you could point it out.

martynj wrote:

  • The GND pin on the DRV8838 does not appear to actually have a ground connection.

The way I have been looking at this circuit is that when PIN 12 of ATT84 is LOW, the NFET is "off". In that state, VMOT and GND are at the same potential (9V in this case). When PIN 12 is HIGH, the NFET is "on", the GND pin of the DRV gets a low impedance path to the ground (via PIN 3 of the NFET). This effectively starts the 9V supply to the DRV. PIN 12 of ATT84 also supplies the 3v to the VCC (that seems to be needed. See below) and in this state the GND of the DRV chip is effectively connected to the common ground. So I think in this state the circuit is OK and hence seems to work on the bench (without the load, I must keep pointing out).

When PIN 12 is LOW (NFET is off), the DRV chip has no GND connection. Is there a problem with this that I should worry about? I suppose if for some reason the output pins in this state also have a path to VMOT and GND, the load will draw current from the 9v supply (but of course, one of the output pins should have a path to VMOT and the other to GND, which, if it is, will be truely nasty! :-)).

As I said in the previous post, when there is no GND connection on the DRV, and VMOT is connected to the positive of the 9V supply, the logic lines (EN and DIR in the schematic) seem to have a path to the GND. That, without the reverse-baised doides I now have on the logic lines from ATT84 to the DRV, was completing the circuit and charging the cap. With the 1N5711 diodes, that seems to have gone away.

Now, when PIN12 is LOW, the cap is not being charged. I have measured current flowing in the circuit (from 3V supply or the 9V supply) is below what my meter can measure (I think <1uamp). When PIN12 goes high, the DRV outputs react as expected to the EN and DIR signals. The 9V battery is also not discharging -- not at least at the rate it was earlier. I have left the circuit connect for over 3 days now and it seems to not drain the 9V battery.

The only unknown left (for me) is if anything would change for the worse when the DRV outputs have a load on them (the solenoid). I am hopeful since in "off" state, I measure 0v across the output pins of the DRV (<0.1mV, which is the least I can measure at home).

  • From the chip schematic, you don't supply 3v to the driver chip - it generates its own internal supply; that pin is just for an external decoupling capacitor.

The driver chip I have in the circuit (not in the schematic) is DRV8838. That requires a separate 3V supply to the VCC pin. After your comment, I did try it without connection to VCC, and the driver does not respond to any changes on EN and DIR pins. Pololu documentation also says that VCC for DRV8838 is required. The A4988 chip in the schematic I have is only for illustration since there is no part for DRV8838 in Fritzing.

  • Yes, large value electrolytics are quite leaky especially as they age. You can minimize this by reducing the value of the capacitor - you only need enough charge to feed the few milliseconds of actuation, any extra is wasted since it will leak away over time. There is a complication here also that breaking the current you have just established in the actuator coil will create a reverse spike that has to go somewhere. Do the actuators have built in diode protection for this or the Pololu board has these built in?

DRV8838 does have a built-in diode protection for the reverse spike. I think (not sure) the DRV8838 chip itself has it. So I am OK there.

As for the capacitor, I am not really sure what value to use. I just saw that the commercially sold controller (the one which I am trying to replace) has a 3300uF cap on it. So I just used the same value. I could try with a smaller one, if that would work.

The alternative is along the lines you have tried but you need a high-side switch - this needs a PFET not an NFET.

I agree. A high-side switch is a possibility. I resisted going that route since the low-side switch seems to be easier to implement than high-side switch. But if the current design throws up some more complication when I connect it to a load, I might have to bit this bullet.

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by sanb 7 months ago

martynj

I have finally made progress. Using the circuit posted in the previous message, I am now able to run the DRV8838/DRV8833 on 6xAA batteries without it leaking continuously. It has been running now for >10 days with no measurable drop in the battery voltage and my meter, which can measure up to 0.1 uAmp does not show a reading for the current drawn.

The 3v battery, which powers the ATT84 MCU and the MOSFET (via PIN10 of the MCU) showed 200uAmp current drawn. Interestingly, I found the replacing the power_adc_enable()/disable() by the following marcos reduces the current to 20uAmp:

#define adc_disable() (ADCSRA &= ~(1<<ADEN)) // disable ADC (before power-off)
#define adc_enable() (ADCSRA |= (1<<ADEN)) // re-enable ADC

I was expecting power_adc_*() functions would work too, but they didn't. If someone knows the difference and why they did not work, I will interested in learning.

While the 20uAmp current in the Sleepy::looseSomeTime() is acceptable, I am interested in knowing:

  1. if this is lowest consumption one can achieve on ATTiny84?
  2. It appears that ATTiny chips can go down to 2-4 uAmp. Is there anything I can do in the code to get down to these values?

The test code I am using is equivalent of the following (the only change being the code that drives the DRV8838 is slightly different from the code for DRV8833):

https://github.com/sanbee/Naarad/blob/FullCmdTO/Nodes/TinyDRV8838/DRV8838Tst/DRV8838Tst.ino

Attached is also the schematic showing the change I am about to make -- namely, connect the RFM69CW to the MCU to command it remotely. What is the current consumption of RFM69CW in the sleep state (via the rf12_sleep() call)? I recall (reading it somewhere on this forum, but can't find now where) that it would few uAmp. Is that correct?

Once this works, I will (finally!) be back to trying @johnO and martynj 's suggestion of using DI05 pin of RFM69CW for logic (perhaps, in the current circuit, to drive the gate of the MOSFET?).

RE: Can the digital I/O pins on the RFM69CW be used to control other logic lines? - Added by sanb 3 months ago

Hi,

Updates from past several months of operation: The circuit I posted in the previous post has now been working very well for many months. It is now continuously powered by 9V battery (6xAA) and the battery drainage is consistent with battery self-drainage. So the problem of current from the battery leaking via the circuit is now fixed. The uC is programmed to send a ping via the RFM69cw every 60 sec. The base-node responds to these pings by sending a command from it's command-queue, or a NoOp. Most of the time, it's a NoOp, which puts the remote mode immediately into sleep mode (the RFM69CW and uC both go into sleep mode and the MOSFET is turned off to cut-off the 9V supply to the DRV8833). The uC can be commanded to turn the solenoid on/off or alter it's ping delays. So a normal operation mode is to (1) send a command to start listening every 10 sec (instead of the default of 60sec), (2) send the command for the solenoid operation (on or off), (3) send a command to set the ping delay back to 60 sec (or whatever is appropriate) and (3) send a NoOp to put the remote node back to sleep. The current drawn from the 9V battery to operate the solenoid is about 2-2.5amp, but only for 15 millisec. So the aggregate power consumption is quite low and my estimate is that the 9V battery should last for at least 2 years.

I have a TMP36 (for temperature) also connected and 60-sec pings carry a local temperature reading as well. My plan for next year is to expand this to control up to 6 solenoids (one at a time). If I can find a cheap uC with similar power consumption (particularly in the sleep mode) as ATT84, and one which I can use JeeLib, but with more I/O pins, I will want to connect as many moisture sensors as possible. Such local data will allow making it "smart". The current "smartness" is really at the base station (which commands this remote node). It checks local weather and makes an estimate of when and if to open the solenoid (e.g., no watering needed if is raining or has rained enough in the past 24 hrs etc.). This has worked well -- correct decisions were made mostly and the plants are happy! :-).

Does anyone know of a uC with larger number of I/O pins than ATT84, but where I can use JeeLib to control the RF69cw and can be programmed using Arduino used as the programmer (ISP)?

Regards,

    (1-12/12)