Noob project needs some critique. EagleCADsoft file attached

Discussion in 'The Projects Forum' started by jameschristian, Dec 7, 2011.

  1. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
    Hey all,

    I am working on a project that tells a fan to turn on for different periods of time according to how a rotary switch is set. Attached is the Eagle CADsoft file for it. It's a first pass at the schematic, and you'll probably see something I need to change to get it to work. I am using a pic16f84 chip to run the thing, and the resistor you see on the schematic represents the fan. I hope I got it right, but if not, your feedback would be greatly appreciated. Thanks in advance! :)

    p.s. I just realized I left off a switch to turn the thing on and off, so I'll be including that for my next go around.
     
  2. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Hi,

    My Eagle don't display anything...

    You could:

    -> click FILE
    -> click EXPORT
    -> click IMAGE

    and saveit as a .PNG-file, and upload that...
     
    jameschristian likes this.
  3. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
    Sry about that, don't know why it won't show, attached is a .png file for you.
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,435
    3,360
    Your Xtal is connected incorrectly and you should pullup MCLR to Vcc via a 10K resistor.
     
    jameschristian likes this.
  5. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
    How should I have connected the xtal? And I had a feeling that the MCLR needed connecting, so thanks a ton for the tip.
     
  6. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
    jameschristian likes this.
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Here, have a look at the attached.

    You can't feed 9v directly to a PIC; they need ~2.5v-5.5v to run.

    I threw in a power switch, a 5v regulator, and caps for them

    I reoriented your crystal, renamed it, and gave it a couple of caps.

    You had both power and ground going to the rotary switch. That wasn't good - there was no connection for power.

    Instead, use the PIC's internal weak pull-ups, and use the switch to connect the inputs to ground.

    I got rid of the unnecessary wires running everywhere and used Vss/Vdd from supply2.lbr.

    I don't know where you got R1 from. Since you didn't really need it anymore, I added R1 from rcl.lbr for the MCLR input.
     
    jameschristian likes this.
  8. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
    Thanks Sgt. Wookie, et al. I saw what you did with the xtal, the voltage regulator and the filtering capacitors, and that all makes sense. The R1 was initially supposed to represent the fan, with one side connected to the R0 out from the uC so as to control when it comes on and for how long. I am still tinkering with the programming but you've helped me along the way. Thanks again for helping me with this project. Regards to you and yours. :)
     
  9. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
    I'd like to add a 'solved' to the title of the post, but can't find a link to do that. Is that possible on this forum?
     
  10. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You don't have to change the topic title.

    However, if you must - Click "Edit" on your original post, and then click the "Go Advanced" button on the bottom. You should be able to change the title. Please leave the original subject, as it's a good one - just add the "solved" thing on the end if you would.
     
    jameschristian likes this.
  11. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
    I don't see an edit button on the original post anymore. I read a forum post that they had taken away the ability to edit posts after a certain amount of time, so is it something that junior members can't do? Also, do you know somewhere i can send my schematic to actually get this thing made? I don't mind doing the soldering, programming, and placement into an enclosure myself on a small scale, but if I can sell a few of these things I'd like to be able to not have to worry about doing all the work if the numbers get high enough. Thanks again :)
     
  12. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I think that members with less than 10 posts have a number of restrictions on them; this is part of the effort to combat spammers. Once you get to 100 posts, you will have less restrictions than that.

    If you want to do it "on the cheap", you might try Batchpcb. you may have to wait a month before your board(s) are paneled with other people's projects - but that's one of the reasons it's cheap.

    better get a few prototypes made before you buy a lot of them - or you will likely wind up with a lot of "coasters".
     
    jameschristian likes this.
  13. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    How does the board look?

    Where in the world are you?
     
  14. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
    Attached is my preliminary board layout. As this is my first project, and something that I would like to actually make, any thoughts on inductive problems or something of that ilk would be great. Also, I noticed the footprint of the crystal is rather large. Is that normal and will it affect the build? Also, I am having trouble with the programming of the PIC itself as I cannot find any good and thorough resource on C programming for pics online. I've included some ode below that I typed out this afternoon which I think is close to being right, but there are some parts that obviously aren't. Anyone out there program PIC's?
    Code ( (Unknown Language)):
    1.  
    2.  
    3. void main ()
    4. TRISA=0        
    5. PORTA=1      //    this command syntax is wrong, but I need to have the Vcc pin turned to input (if that's even necessary to do).
    6.                    // I also need to get the RA0 to output to power the fan
    7.                    
    8. if (TRISA=1)      // didd this to say 'if the power switch is on, proceed'
    9. {
    10.         if (PORTA1=1)        //   this is supposed to be the port that the first pin of the rotary switch is connected to
    11.            {
    12.              delay_ms(6*10e3)    //   one minute of fan time,
    13.                                               and I know the delay cmd is wrong,
    14.                                               //    but is there something similar that will     turn the port on for a given time without having to compute a bunch of NOPS?
    15.          else if (PORTA2=1)
    16.            {
    17.               delay_ms(12*10e3)
    18.            }                                //     here the 'on' time would be for two minutes
    19.           else if (PORTA3=1)         //     this syntax may be wrong to designate the RA1-7 ports,
    20.                                  //      but it's the best I can do for the moment
    21.            {
    22.               delay_ms(30*10e3)    //five minutes this time
    23.            }
    24.                else if (PORTA4=1)        // you get the idea....
    25. }
    26. return(0)
    27.  
    By the by, I live in the southern U.S. :)
    And I can't attach another file yet apparently. Oh well. I'll try to upload a screenshot and post a link.
     
    Last edited: Dec 8, 2011
  15. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
  16. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
    Did some research and got this far....

    Code ( (Unknown Language)):
    1. #include <pic.h>
    2.  
    3. void main()
    4. {
    5. TRIS A==0       //sets output to fan
    6. PORTB==0       //CLEARS PORT B
    7.  
    8. if (TRISB0==1)
    9. {
    10. TRISA==1
    11. delay_ms(6*10E3);     //ONE MINUTE ON
    12. }
    13. else if (TRISB1==1)
    14. {
    15. TRISA==1
    16. delay_ms(12*10E3);      //2 MINUTES ON
    17. }
    18. ELSE IF (TRISB2==1)
    19. {
    20. TRISA==1
    21. delay_ms(30*10e3)       //5 MINUTES ON
    22. }
    23. else if (TRISB3==1)
    24. {
    25. TRISA==1
    26. delay_ms(60*10e3)         //10 MINUTES ON
    27. }
    28. else if (TRISB4==1)
    29. {
    30. TRISA==1
    31. delay_ms(120*10e3);      //20 MINUTES ON
    32. }
    33. else if (TRISB5==1)
    34. {
    35. TRISA==1
    36. delay_ms(180*10e3)       //30 MINUTES
    37. }
    38. else if (TRISB6==1)
    39. {
    40. TRISA==1
    41. delay_ms(360*10e3);      //ONE HOUR ON
    42. }
    43. else if (TRISB7==1)
    44. {
    45. TRISA==1
    46. delay_ms(720*10e3)     //2 HOURS ON
    47. }
    48. }
    49. return ()
    50.  
    Do you think this will run correctly? I will compile it tonight or tomorrow and let you know if I get any errors. Here's hoping...
     
    Last edited: Dec 8, 2011
  17. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You were missing a bunch of semicolons.
    I re-indented your code for you using Notepad++.
    It's much easier to read C code if it is indented properly.
    There is no loop for the code; it'll run through once and crash into the end.

    I don't know what the prototype is for the delay_ms(numbertype) function; if it is an integer, the max ms will be 32767; unsigned int will be 65535. 60*10E3 will overflow the 1st, 120*10e3 will overflow the 2nd.
    You need to create a function called delay_sec() that accepts an integer, and executes a for loop that calls delay_ms(1000); something like:

    Code ( (Unknown Language)):
    1. void delay_sec(int secs)
    2. {
    3.    for(int ms=0;ms<secs;ms++)
    4.    {
    5.       delay_ms(1000);      // delay 1 second
    6.    }
    7. }
    8. return ();
    As a bonus, you will eliminate a lot of multiply operators, which otherwise would have caused "code bloat". Multiplication operations are replaced with lots of code that does multiple adds in a loop. Using a subroutine like this means there is only one loop that does the adds.

    Code ( (Unknown Language)):
    1. #include <pic.h>
    2.  
    3. void main()
    4. {
    5.    TRIS A==0;      //sets output to fan
    6.    PORTB==0;       //CLEARS PORT B
    7.  
    8.    if (TRISB0==1)
    9.    {
    10.       TRISA==1;
    11.       delay_ms(6*10E3);     //ONE MINUTE ON
    12.    }
    13.    else if (TRISB1==1)
    14.    {
    15.       TRISA==1;
    16.       delay_ms(12*10E3);    //2 MINUTES ON
    17.    }
    18.    ELSE IF (TRISB2==1)
    19.    {
    20.       TRISA==1;
    21.       delay_ms(30*10e3);    //5 MINUTES ON
    22.    }
    23.    else if (TRISB3==1)
    24.    {
    25.       TRISA==1;
    26.       delay_ms(60*10e3);    //10 MINUTES ON
    27.    }
    28.    else if (TRISB4==1)
    29.    {
    30.       TRISA==1;
    31.       delay_ms(120*10e3);   //20 MINUTES ON
    32.    }
    33.    else if (TRISB5==1)
    34.    {
    35.       TRISA==1;
    36.       delay_ms(180*10e3);   //30 MINUTES
    37.    }
    38.    else if (TRISB6==1)
    39.    {
    40.       TRISA==1;
    41.       delay_ms(360*10e3);   //ONE HOUR ON
    42.    }
    43.    else if (TRISB7==1)
    44.    {
    45.       TRISA==1;
    46.       delay_ms(720*10e3);   //2 HOURS ON
    47.    }
    48. }
    49. return ();
     
    Last edited: Dec 9, 2011
  18. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You need to upload your current schematic and board files. They need a little help.

    The crystal library model you used is HUGE! :eek: Does your actual crystal look like that?
     
  19. jameschristian

    Thread Starter Member

    Nov 24, 2011
    58
    0
    Ok, first of all, I need to just say thanks. I have been a few boards (sorry old habit of calling a forum a bulletin board) and this one has been by far the most helpful. So just know that you guys are great. I wish you would teach a class online so I could just soak up the knowledge, Sgt. Wookie, because you're above and beyond my prof here. They are phasing out teaching about microcontrollers and he couldn't care less about my little project. Ok, nuff said on that.

    As per the crystal, yes, it is huge, and no, that is not what my crystal looks like. I bought a bag of them on ebay a few months ago, they are 20Mhz crystals and look like little silver 'half cylinders' (I am sure you know what I am talking about) with two leads and a flattened top. I just didn't know the part number and couldn't look it up because it's been too long for ebay's servers to carry the info any more. I uploaded my board and schematic file for your perusal, and am wondering if there are going to be inductance issues somewhere. I am trying to limit the PCB in terms of size because of cost, but if I need to rearrange things to get them to work properly, then of course I will do so.

    Again, thank you for being helpful when others were not. It is a great boon to guys and gals like me that guys and gals like you will take a few minutes to give gentle correction rather than the flame sessions I have encountered on other sites. I will work on the code in a few minutes and post my revisions there too. Regards.
     
  20. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    We try hard to remember that we were also beginners once upon a time.

    I try to help people as I would have liked to have been helped back in the day.

    OK, what is the actual distance between the two pins on your crystal?

    Better yet, can you create a simple .sch called "MyCrystal" and simply draw the image in the schematic? Turn the grid on, and measure the crystal carefully, and replicate what it looks like in the schematic drawing area. Most important is the "footprint" - how much actual area it will cover on the board, the spacing of the two leads, and exactly where the leads are in the footprint.

    Do the best you can. We can go back and fourth a few times until you are happy with it.

    I have to leave for awhile, but I'll be back later.
     
Loading...