Go Down

Topic: DCDW = Dirt Cheap Dumb Wireless (Read 23 times) previous topic - next topic

martin_bg

would it be possible to have the code run on interrupts rather than a counting loop? that would make this whole thing easier / practical.





tkbyd

Code: [Select]
Would it be possible to have the code run on interrupts rather than a counting loop?

Here's the thing... As I understand it. AltairLabs may come in on this an correct me...

When no DCDW is transmitting, the receiver "listens" harder and harder, and before long starts "hearing things". At that point, the output of the receiver starts generating lots of spurious positive and negative edges... which would divert the Arduino excessively inside a fancier interrupt handler.

With the simple interrupt handler and more code (which taps into what the simple handler is picking up), selectively executed, a happy compromise can be had. The Arduino will do very little with the "noise", but will from time to time make a check to see if more than noise is coming in.

AltairLabs

#7
Jan 22, 2011, 02:36 am Last Edit: Jan 22, 2011, 02:38 am by AltairLabs Reason: 1
Howdy @martin_bg

Quote
would it be possible to have the code run on interrupts rather than a counting loop? that would make this whole thing easier / practical.
Thats just what we thought too.  Interrupts was my very first approach, and it *does* work.  But there turned out to be less advantage than I had hoped, and some unexpected drawbacks.

(1) the RX noise of an empty channel on these cheeep OOK radio links will consume significant CPU time servicing the interrupt, even to return a result code of "nothing coherent received".

(2) interrupts are only available for certain I/O pins, the new approach is possible for any I/O pin

(3) interrupts corrupt other Arduino functions such as the millis() counter.

So after trying both techniques a while, the interrupts seemed much less attractive.  You can still do interrupts if you wish, it would probably work best for a continuous transmit or a quiet link like "real" radios with squelch.  Maybe cheeep walkie talkies?

Heres some early code that was interrupt based.

Code: [Select]
// Dirt Cheap Dumb Wireless
// by AltairLabs <http://www.altair.org>
// This example code is in the public domain.
//
// see www.DCDDumbWireless.com



int normLED = 13;      // the on-off LED is digital pin 13
int RXpin = 2;         // DCDW data link on digital pin 2
volatile int dataComingIn = 0;
int pulses = 1000;      // total number of pulses to time
int pulse;             // pulse count
unsigned long timeout= 100000;   // microsecs to wait before giving up
unsigned long t0;      // start time hack
unsigned long time;    // delay in millisec
unsigned long duration;  // length of one pulse
long frequency;        // frequency of pulse train


void setup()
{
 pinMode(normLED, OUTPUT);
 pinMode(RXpin, INPUT);           // set RX pin to input
//  digitalWrite(RXpin, HIGH);       // and turn on pullup resistor
 Serial.begin(9600);              // start up the serial communications USART
 Serial.println(" ");             // test the comm port
 Serial.println("Good morning, Dr. Chandra.  This is HAL.");    

 attachInterrupt(0, blink, HIGH); // grab interrupt for digital pin 2

}


void loop()
{
 digitalWrite(normLED, LOW);   // set normLED off when in main
// pulse measurement goes here
 if (dataComingIn != 0) {
   frequency = countFrequency();
 }
 if (frequency > 0) {
   Serial.print("Heard Freq = ");  Serial.println(frequency);                
 }
 if (frequency < -1) {
   Serial.print("Freq count abandoned on pulse ");  Serial.println(frequency);                
 }
             
/*  while (dataComingIn) {
   digitalWrite(normLED, LOW);   // set normLED off when in main
   duration = pulseIn(RXpin, LOW, timeout);
   if (duration == 0) {dataComingIn = 0;}  
 }
 */
 dataComingIn = 0;
 Serial.println("Main Loop Idle");                
 delay(1000);
 
}
 
long countFrequency ()  
{
 frequency = 0;                              // nothin' yet
//  Serial.print("counting  ");
 t0 = millis();                              // start time
 for(pulse = 0; pulse < pulses; pulse += 1)  // count pulses
 {                                  
   duration = pulseIn(RXpin, LOW, timeout);
   if (duration == 0)
   {
//      Serial.println("abort countFrequency");                 // delta time
     dataComingIn = 0;  
     return -(long)pulse;
   }
 }
 time = millis()-t0;                                    // time = now - start
//  Serial.print(" "); Serial.println(time);               // delta time
 frequency = 1000 * (unsigned long)pulses / time;
//  Serial.println(frequency);                 // frequency in Hz
 return (long)frequency;
}  

void blink()
{
 digitalWrite(normLED, HIGH);   // set normLED on when in interrupt
 dataComingIn = 1;              // set flag for incoming data pulse train
}


If you would like to run with the interrupt approach, our second set of PC boards may be ordered soon.  At this early stage we cant give much support to "appliance operators" but if you are proficient with schematic and soldering iron youre welcome to join the development.

AltairLabs

Howdy, @OSGrill

Quote
I'm very interested in seeing just how small a sensor can be made (thermo).
The goal is to create a probe that can be used in a wireless meat thermometer, so ultra-high precision and fast cycling/updating is not necessary.  Long battery life, small probe size and a 2-4m transmit distance are the objectives.

Been thinkin 'bout your meat thermometer idea, the DCDW concept fits well for you.  

The two approaches I see are
(1) the single dedicated sensor.  You dont need the quad NAND at all., just use Osc C to send temp.  Updates as often as you care to read it.  It runs all the time and uses the least components.  You can even snap off and discard one half of the circuit board.

(2) use Osc C to switch on Osc B every N seconds for an updated reading.  This uses the full circuit board with both chips and conserves battery life.

We are not prepared to support newbies, we still need good explanations, diagrams and other documentation for the various modes, and a better introduction to the possible modes and how to choose.  But if you are proficient with schematics and designing simple circuits, you are welcome to use these ideas.  After all, that what Open Source is all about:)

The DCDW circuit board is a bit bigger than a 9V battery.  You could use one to prototype your circuit and test your code, when you are satisfied with the design you could make your own dedicated PC board out of surface mount components, I reckon the size could be reduced to about an inch square.

The antenna wants to be nearly 20 inches, working against a ground at leeast the same size.  nobody really wants a 40 inch meat thermometer so the antenna will be a compromise.  Probably enclose the thermistor in a thin stainless steel tube, make that "ground".  Then have a plastic head to hold battery and PCB and maybe a power switch.  The antenna can be a wire coiled up inside the head.  The RF modules claim a range of hundres of feet with "proper" antenna so you should still get enough to reach a few meters.

If you can glean enough from this post to run with the idea on your own, thats great we can put you down for a beta test board.  If the details still seem fuzzy to you , please be patient while we develop better documentation and code examples.  Either way hit the website and give us an email, we'll keep ya posted.

AltairLabs

OKAY here is a major annoyance.  The CD4093 from Texas Instruments is purportedly a Quad 2-Input NAND with Schmitt trigger inputs.  DCDW depends on the "gated oscillator" or "astable multivibrator" touted by National Semiconductor and Texas Instruments, respectively.



OK fine, that exactly what we want, right down to those equations giving the transition times.  The timing dont depend in ANY WAY on the voltage at the Control input, that just turns the oscillator on and off RIGHT?  Thats the beauty of a Schmitt trigger input, RIGHT?  Can I get an AMEN on that?

Well heres what REALLY happens when I use the Texas Instrument part and vary the control voltage.



The osc freq varies 10X as the control voltage drops, before it shuts off.  WHERE is the Schmitt Trigger?  I'll be in contact with TI about this, as well as ordering equivalent parts from the other 3 suppliers represented at Digi Key.

In the mean time we would greatly appreciate hearing from anyone about this.

Go Up