Close

SPI without a clock?

A project log for Well well

Monitoring the monitor that monitors the well

darrin-bDarrin B 06/16/2022 at 16:590 Comments

Looking at various widths of ones and zeroes that I had captured, I settled on a 220 uSec. bit width, clocking it with a timer. It was an ugly hack

  1. Wait for 150 mSec. of zero
  2. Wait for the rising edge
  3. Wait 1/2 of a bit width
  4. Capture the first bit
  5. Start the 220 uSec. clock
  6. Capture the next bit when the timer has elapsed
  7. Repeat step 6 until all 32 bits are received
  8. Send the value to the PC

Before long, I added some ANSI terminal control values to the data to format the captured data. Only one value appeared to change. I don't have many of the notes I made during this time, so I'll skip ahead a bit. Eventually I worked out the bit order and whether, or not, to invert the incoming bits and that considering the data as two 16 bit values made the most sense.

The upper 16 bits are in the range of 0x9001 to 0x9012, while the lower 16 ranged from 0x45 to 0xffff. Only the value attached to 0x9011 varied over time, hovering at about 0x9a0. That happens to be 2464, 10 times the phase to phase voltage that the pump is connected to. Not much happened until the well pump turned on while I was working on this project. While the pump ran, 0x9010 and 0x9012 were also changing. My antique clamp-on AC ammeter showed about 11 amps while the pump ran, while the number reported by the monitor was bouncing around 0x450. Looks like these are the operating current values, though scaled by 100.

Knowing voltage and current and being able to detect the running time, there are a number of faults that can be detected. I must build something! But first the software controlled timer needed to be improved, it would generate 33 interrupts for each incoming value. I'd like to save some CPU cycles for other uses, could I use the SPI interface to collect the data? I'll need a clock source. A bit of re-wiring the Z8 dev board and rewriting code reduces the load to just 5 interrupts per incoming value, much better. The IR detector is now connected to both the SPI data input and a GPIO pin and a timer's output is connected to the SPI-CLK, watch what hppens

  1. Configure a timer for a 220 uSec. period and preset the timer count to slightly less than 110 uSec.
  2. Wait for 150 mSec. of zero
  3. Set and enable the GPIO to interrupt on a rising edge
  4. On the GPIO interrupt, disable the GPIO input, enable the timer for continuous operation
  5. SPI receiver will interrupt when it receives a byte, store it
  6. When the fourth byte is received, disable the timer and preset the count to the value used in step 1, re-enable the GPIO interrupt
  7. Since we are waiting for the GPIO interrupt, the main loop is free to process all sorts of things.

Discussions