Pages: [1] 2   Go Down
Author Topic: Can SPI overload my UNO if called too much?  (Read 1216 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This test code makes my LCD freeze up:
Code:
void loop() {
  if (millis() - lcdTime > 2000) { //Has it been 2 seconds yet?
    lcdTime = millis(); //update the timer
    UpdateLCD(); // Change the LCD messege
  }   
    ReadTimeDate(); //UPDATE THE TIME VARIABLES
  return;

If I move the ReadTimeDate() function inside the 2 second waiting period, it works fine, like this:
Code:
void loop() {
  if (millis() - lcdTime > 2000) { //Has it been 2 seconds yet?
    lcdTime = millis(); //update the timer
    UpdateLCD(); // Change the LCD messege
    ReadTimeDate(); //UPDATE THE TIME VARIABLES
  }   
  return;

Here is the ReadTimeDate() function:
Code:
void ReadTimeDate(){
  String temp;
  for(int i=0; i<=6;i++){
    if(i==3)  i++;
    digitalWrite(cs, LOW);
    SPI.transfer(i+0x00);
    unsigned int n = SPI.transfer(0x00);       
    digitalWrite(cs, HIGH);
    int a=n & B00001111;   
    if(i==2){
      int b=(n & B00110000)>>4; //24 hour mode
      if(b==B00000010)  b=20;       
      else if(b==B00000001)  b=10;
      TimeDate[i]=a+b;
    }
    else if(i==4){
      int b=(n & B00110000)>>4;
      TimeDate[i]=a+b*10;
    }
    else if(i==5){
      int b=(n & B00010000)>>4;
      TimeDate[i]=a+b*10;
    }
    else if(i==6){
      int b=(n & B11110000)>>4;
      TimeDate[i]=a+b*10;
    }
    else{
      int b=(n & B01110000)>>4;
      TimeDate[i]=a+b*10;
    }
  }
  temp.concat(TimeDate[rtcMonth]);
  temp.concat("/") ;
  temp.concat(TimeDate[rtcDay]);
  temp.concat("/") ;
  temp.concat(TimeDate[rtcYear]);
  temp.concat("     ") ;
  temp.concat(TimeDate[rtcHour]);
  temp.concat(":") ;
  temp.concat(TimeDate[rtcMinute]);
  if (debugMode) {
    Serial.println(temp);
  }
}

...did I fix the problem, or just make it where it won't happen as often.  I don't want to just mask a problem that will show up less frequently. Thanks.
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This code also makes things freeze, but it seems delay(100) should be plenty of time?
Code:
void loop() {
  if (millis() - lcdTime > 2000) { //Has it been 2 seconds yet?
    lcdTime = millis(); //update the timer
    UpdateLCD(); // Change the LCD messege

  } 
     ReadTimeDate(); //UPDATE THE TIME VARIABLES
    delay(100);
  return;
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34572
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why are you putting a return at the end of your loop? And why is there no closing brace?
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I missed the closing bracket when I cut/paste.  The return was to remove all other events, trying to narrow the problem.
It seems that just touch the pins on the back of the UNO's chip (DIP version) cause resets, and sporadic stuff.  Is this normal?  My hands are clean, dry, I'm in an A/C environment... 
This was my first attempt at using a chip/crystal/and smd caps. ...I think it'll be my last!  I like the pro-mini.
Here's a photo of my board.  Should it be this sensitive?
I didn't put of ground plane on either side after I finished my traces in Eagle, does that matter?


* photo 2.JPG (456.42 KB, 960x1280 - viewed 15 times.)

* photo 1.JPG (484.44 KB, 960x1280 - viewed 16 times.)
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34572
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It seems that just touch the pins on the back of the UNO's chip (DIP version) cause resets, and sporadic stuff.  Is this normal?
No, it implies that there is some floating inputs.
Can you post the schematic and ALL the code?
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

schematic...

* 1554E v2.0.brd (135.4 KB - downloaded 4 times.)
* 1554E v2.0.sch (244.8 KB - downloaded 8 times.)
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34572
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Any chance of actually posting the schematic, not an Eagle file that won't load with my freeware version.
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry. Here it is.  And also the code.  It's broken out into different tabs so I had to zip it up.

* 1554E v2.0.pdf (39.45 KB - downloaded 14 times.)
* Chicken_Coop_2_6.zip (8.13 KB - downloaded 5 times.)
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One change I made, the SMD caps for the crystal are 22pF, not .1 uF which I tried first! 
I'm wondering if I need to go back to PTH caps and resisters, and forget SMD. 
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34572
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for that. I was looking at the schematic and my wife said "what are you doing". I said that I was looking at a schematic from someone and it would not work. She said "there won't be enough decoupling then" and she was right.
Quote
forget SMD.
No SMD is the way to go. However, I noticed that on the schematic you have just one 0.1uF on the motor control IC and yet on the photo that seems to be on the LCD.
You need a cap on the processor's Aref and one on each chip. I would also put some more round the motor and +12V supply. Just solder them on between the pins on the board.
The power regulator can also do with some 0.1uFs as well as the bulk values you have.
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

possibly having buttons (but I don't push them) on the RX an TX pins causes issues.  ...I do declare them as inputs and turn on the internal pull-ups  
Anyway, I've about have it with bare chip IC and smd parts.  I'm going to start over with the pro mini, and maybe even throw in a serial LCD for good measure.
One question, though.  Is this SPI DS3234 RTC breakout from Sparkfun a real solid interface?  It connects via SPI, which is my first experience with such.  I use an I2C chip last time.  Is SPI real finicky?  

EDIT.  Your's just came in.  So your wife is on top of these things!  Great.  Well, I'll take a break, a walk, and check it out some more before throwing in the towel...  I would like to do some SMD if I knew it was reliable.
Thanks,
Logged

Maryland, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 162
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For complete giggles, can you try something?

In rtc.ino ReadTimeDate function, comment out EVERYTHING involving the "String" class (the declaration and all the temp.concat lines) and just put some simple message in place...

Then try running it outside of the every-2-second condition and see if it helps.
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks GrumpyMike.  I decided to give it one more whirl, and I think I'll be able to salvage the board.  Here's what I did:  BatchPCB sent an extra board (which they always do, !:), so I put the bare minimal on to start.
Atmega328
crystal, 22 pf caps
0.1 uF between GND & Vcc
0.1 uF between Aref and GND

then the 10K resister to ground from the reset, and the 0.1 uF cap to DTR
Then scrubbed it with alcohol and toothbrush.

No other parts populated.  Then I hooked it up to my FTDI cable and loaded a sketch.  It worked.  I modded the Serial example of ascii table to keep running/sending the table over and over.

Now, when I finger the back of the board/pins lightly, it continues to work, but if I handle it pretty good, the serial stream bleeps and blips.  After some experimenting, I see it mainly happens when I touch the two pins of the crystal.  (they're all cut clean, short).  So I hook up my store bought UNO and load the same sketch on it, and I discover that if I handle it fairly forcefully on the pins, I can reproduce the same thing.  So I am assuming things are okay, and that this isn't going to flake out after a years' time. (it's a gift).  Does it sound trust worthy to you?
Thanks,
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34572
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and I discover that if I handle it fairly forcefully on the pins, I can reproduce the same thing.
Yes touching a circuit adds a bit of capacitance and a high resistance to it. So as the crystal has only 22pF capacitors it is easily upset by say doubling this capacitance.
The "laying on of hands" is an old fault finding trick that often bemuses onlookers. However don't use it on high voltage circuits like a TV.

Quote
So I am assuming things are okay,
Yes it sounds like it.  smiley
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great!  I've done a few projects but never ran into this.  Likely, because I've always worked with the pro mini.  Thanks again.  I'll post the final product if anyone's interested.  It's version 2 of my chicken coop door, slimmed down to the size of a deck of cards, and still has an LCD.
Logged

Pages: [1] 2   Go Up
Jump to: