Pages: 1 [2]   Go Down
Author Topic: scanning 25 bcd switches - wrong reading?  (Read 1991 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 518
Posts: 26371
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't see anything unreasonable; but I'm not really a programmer, I just play one on  TV smiley-cool
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice one Bob,    like with the remote control !   smiley

I think I have inadvertently fixed the problem ( I hate to say that too soon but it has been ok for the last 8 hours when I try it )

Just before I posted the code, I forgot I had tried putting in a delay right at the end of the scan function, so that the clock pulse to the cascaded counters had a bit of time at a high level.

Without it the next instruction was to take it low again.  I don't know how to work out how long that takes,  but the data sheet for the 4017 says the clock pulse at 5v should be minimum 200nS.     3.2 clock pulses @ 16Mhz?

The wiring to the  perf board and the 3 chips clock inputs has quite a bit of capacitance too, and there is a 22k resistor feeding each counter for the diode "anding"

I guess it was tripping over its own feet ?  I will test it again in the morning,  and perhaps reduce the delay to a couple of milliseconds, I can see it is noticeably slower with 20mS  x  20 loops.   nearly half a second.
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well the remote is still working, but now the decoder has frozen,  its getting data from the receiver OK, but not responding, no output scoped on the data out from the micro.

I reset the power and now it works again.....

Can anyone see in my code why it should hang up?

It reads the switch data, compares the PIN numbers ( a security address ) then I sort out the displays that need leading zero blanking,  plus I check to see if switches 7 and 8 are set to 0, ( which is how I put the displays into standby )  and then it shiftsout to the 19 shift registers.

I put the flushing bit in when I had the previous problem, I dont think it can do any harm ?

There is a shift register clear pin on the TPIC display chips, but I am not using that ( or the notG pin for blanking  ) due to pcb layout simplicity.  heres the code:-
Code:
//  19 digit receiver
// tile order set by old pcb layout of plugs  HGDABCEFSRQPONMLKJI link across gap data inout
// try flushing SR before sending new lot to get rid of intermittent wrong displays

#include <VirtualWire.h>
#define latchPin 19  // rck
#define clockPin 18  // sck
#define dataPin 16   // ser in
int Rxpin;
int PIN;
int tile [19];

int SW0Pin = 3;               // bits to read in unique address - LSB
int SW1Pin = 4;               // bits to read in unique address
int SW2Pin = 5;               // bits to read in unique address
int SW3Pin = 6;               // bits to read in unique address - MSB
int address = 0;            // bits put together afteer reading switches
int add0;
int add1;
int add2;
int add3;

const byte digitTable [10] = {
  B01111110, B00110000, B01101101, B01111001, B00110011,      // orig without text switching
  B01011011, B01011111, B01110000, B01111111, B01111011};

const byte blank = B00000000;

void setup()
{

  pinMode(SW0Pin, INPUT); // LSB of remote Address
  digitalWrite(SW0Pin, HIGH);
  byte add0 = 0; // read the value of SW0
  pinMode(SW1Pin, INPUT); // LSB+1
  digitalWrite(SW1Pin, HIGH);
  byte add1= 0;
  pinMode(SW2Pin, INPUT);  // LSB+2
  digitalWrite(SW2Pin, HIGH);
  byte add2 = 0;
  pinMode(SW3Pin, INPUT);  // MSB of address
  digitalWrite(SW3Pin, HIGH);
  byte add3 = 0;

  add3 = !digitalRead(SW3Pin);
  add3 = add3 << 3;
  add2 = !digitalRead(SW2Pin);
  add2 = add2 << 2;
  add1 = !digitalRead(SW1Pin);
  add1 = add1 << 1;
  add0 = !digitalRead(SW0Pin);
  address = address|add3;
  address = address|add2;
  address = address|add1;
  address = address|add0;

  Rxpin = address;
  Serial.println("Rx PIN is: ");
  Serial.println(Rxpin, BIN);
  Serial.println("testing");
  Serial.begin(9600); // Debugging only
  Serial.println("setup");

  pinMode ( latchPin, OUTPUT);
  pinMode ( clockPin, OUTPUT);
  pinMode ( dataPin, OUTPUT);

  vw_set_rx_pin(9);        // set Rx
  vw_setup(2400); // Bits per sec
  vw_rx_start();    
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop ()
{

  //        CHECK FOR INCOMING MESSAGE
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
  delay (20);
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    Serial.println("Got: ");  // Show on PC for debugging

    //            CHECK IF PIN NUMBERS MATCH

    PIN = buf[0];   // read Tx PIN number from buffer 0
    if ( PIN == Rxpin ) {   //  everything below only runs if PINs match

      Serial.println(" PINs match ") ;
      
      for ( int t =1 ;t<=19;t++ ) {
        tile [t] = buf [t];
          show ();
      }
    } // end of if PINs match
  }//  end of if message received
}  //  end of loop


void show ()

{   //   display numbers generated depending on leading zero blanking requirements of each group of displays
  int dnumber = digitTable [ tile [3] ];  // single digit , no LZblanking
  /////////////////////////////////////////////////////
  int gnumber = (tile [2]) ? digitTable [ tile [2]] : 0; // leading zero blanking

  int  hnumber = digitTable [tile [1]];
  ////////////////////////////////////////////////////
  int enumber = (tile [7]) ? digitTable [ tile [7]] : 0; // leading zero blanking

  int  fnumber = digitTable [tile [8]];
  ////////////////////////////////////////////////////
  int rnumber = (tile [10]) ? digitTable [ tile [10]] : 0; // leading zero blanking

  int  snumber = digitTable [tile [9]];
  ////////////////////////////////////////////////////

  int anumber = (  tile [4]) ? digitTable [ tile [4] ] : 0;
  int bnumber = ( tile [4]|| tile [5]) ? digitTable [ tile [5]] : 0; // leading zero blanking
  int  cnumber = digitTable [tile [6]];

  ///////////////////////////////////////////////////////
  int onumber = (  tile [13]) ? digitTable [ tile [13] ] : 0;
  int pnumber = ( tile [13]|| tile [12]) ? digitTable [ tile [12]] : 0; // leading zero blanking
  int  qnumber = digitTable [tile [11]];

  ////////////////////////////////////////////////////

  int lnumber = (  tile [16]) ? digitTable [ tile [16] ] : 0;
  int mnumber = ( tile [16]|| tile [15]) ? digitTable [ tile [15]] : 0; // leading zero blanking
  int  nnumber = digitTable [tile [14]];

  ////////////////////////////////////////////////////

  int inumber = (  tile [19]) ? digitTable [ tile [19] ] : 0;
  int jnumber = ( tile [19]|| tile [18]) ? digitTable [ tile [18]] : 0; // leading zero blanking
  int  knumber = digitTable [tile [17]];

  ////////////////////////////////////////////////////

if ( tile [7] || tile [8] ) {     // if switches 7 and 8  set to 00 blanks all displays
  
   ///////////////////////////////////////////////////
    digitalWrite(latchPin, LOW);
    
   for ( int k=0; k<=20; k++ ){                            // flush out shift register
    shiftOut(dataPin, clockPin, LSBFIRST, blank);
   }
    delay (20);

    shiftOut(dataPin, clockPin, LSBFIRST, hnumber);  
   // delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, gnumber);
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, dnumber);
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, anumber);
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, bnumber);  
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, cnumber);
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, enumber);
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, fnumber);
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, snumber);  
   // delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, rnumber);
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, qnumber);
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, pnumber);
   // delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, onumber);  
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, nnumber);
    //delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, mnumber);
   // delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, lnumber);
   // delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, knumber);
   // delay (5);  
    shiftOut(dataPin, clockPin, LSBFIRST, jnumber);
   // delay (5);
    shiftOut(dataPin, clockPin, LSBFIRST, inumber);
    delay (5);

    digitalWrite(latchPin, HIGH);
  }
  else {

    digitalWrite(latchPin, LOW);      // blanking all displays
   for ( int k=0; k<=20; k++ ){
    shiftOut(dataPin, clockPin, LSBFIRST, blank);
   }
  digitalWrite(latchPin, HIGH);
 }
}  // end of showT function




« Last Edit: June 13, 2011, 11:04:03 pm by Boffin1 » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Pages: 1 [2]   Go Up
Jump to: