Simple microcontroller schematic (using Proteus)

Discussion in 'General Electronics Chat' started by Gump, Nov 20, 2011.

  1. Gump

    Thread Starter Member

    Jun 7, 2010
    57
    1
    Hello,

    Firstly, I'm using the demo version of ISIS Professional.

    I've got the following schematic (see uploaded schematic), and this is what the work area looks like when the simulation is running. Notice that even though the button is down there is no current through the ammeter. Similarly, pin 6 (RB0) should be red (not blue) indicating it is high.

    As for the power connections that aren't shown on the schematic (some reason ISIS cannot link the "PICVDD" to the PICVDD defined on the PIC microchip without a power rail configuration) as it isn't exactly 2V due to the resistors: PICVDD connects to +2V power rail.

    What could I be doing wrong here?

    Thanks.
     
  2. Gump

    Thread Starter Member

    Jun 7, 2010
    57
    1
    Don't suppose anybody has any suggestions?

    Thanks.
     
  3. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    This is just a shot in the dark; I know nothing about ISIS (or any other simulator) and my experience with PIC's is only with the PICAXE variants. In addition, I don't know what the circuit is supposed to do, or whether you actually have built it or are just simulating it, so my comments are probably irrelevant. But since no one else has offered anything, I'll speculate.

    Are you sure that the crystal is oscillating? Is it properly positioned with no signal tracks running under it? Is it on an isolated groundplane? Are you sure about the placement of the 30 pF caps; my (fallible) memory tells me that other schematics I have seen show them connected from each crystal lead to ground as opposed to in parallel with the signal leads.
     
  4. Gump

    Thread Starter Member

    Jun 7, 2010
    57
    1
    Hi tracecom,

    Thanks for the comment, well I am only simulating everything so far... All that should happen is that when the button is pushed, RB7 should be set high. The code for the PIC is trivial:

    Code ( (Unknown Language)):
    1.  #include <16F84A.h>
    2. #FUSES NOWDT
    3. #FUSES LP
    4. #FUSES PUT
    5. #USE delay(clock=32kHz)
    6.  
    7. void main(){
    8.    while(true){
    9.       if(input_state(PIN_B0)==1){
    10.          output_high(PIN_B7);
    11.       }else{
    12.          output_low(PIN_B7);
    13.       }    
    14.    }
    15. }

    I've tried the code below which just switched B7 high and low every second, and that is working just fine when simulated:

    Code ( (Unknown Language)):
    1. #include <16F84A.h>
    2. #FUSES NOWDT
    3. #FUSES LP
    4. #FUSES PUT
    5. #USE delay(clock=32kHz)
    6.  
    7. void main(){
    8.    int1 mHigh=false;
    9.    while(true){
    10.       if(mHigh==true)
    11.          output_high(PIN_B7);
    12.       else
    13.          output_low(PIN_B7);
    14.       mHigh=!mHigh;
    15.       delay_ms(1000);      
    16.    }
    17. }
    Well, I am guessing yes as the code above works fine in the simulator, but I don't know if this would have anything to do with the inputs not working, as for the simulator you set the speed of the PIC within the pic property page, so the simulator doesn't use the crystal oscillator it seems.

    There's nothing other than what you see.

    To be honest I'm not quite sure, I've got a book called "Pic in practice" which shows them wired that way, but I'm not sure.

    Thanks.
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You circuit diagram is not anything you should try in a real world setup. What are you trying to do? It could also be that the model used for the PIC is not 100 accurate. Or say more a ideal model more than a practical model. I know you simulator is shipped with a lot examples for PIC. Have you looked at these examples?
     
  6. Gump

    Thread Starter Member

    Jun 7, 2010
    57
    1
    Hello t06afre,

    Why is this?

    Nothing more than getting the microchip to respond to an input (which never seems to arrive).

    I have and they seem to work absolutely fine, which is what is confusing as they're a lot more complex (driving LCD displays etc.) than a simple push button.

    Thanks.
     
  7. T.Jackson

    New Member

    Nov 22, 2011
    328
    14
    Yeah we need to know what the project goal is man, otherwise you're just gonna drive us all bananas.
     
  8. T.Jackson

    New Member

    Nov 22, 2011
    328
    14
    You should try and do some PC programming (like Java) -- before you dive in and begin learning C for PICs. Not easy mate, you'll do your head in if you have no programming experience.
     
  9. Gump

    Thread Starter Member

    Jun 7, 2010
    57
    1
    I push a button that is connected to a pin on the PIC. The PIC checks if the pin is high and if so sets some other pin high, otherwise it is set to low. That's it...

    The programming isn't a problem at all, I'm very experienced with traditional languages such as those. I'm just not seeing why the input isn't working.

    Thanks.
     
  10. T.Jackson

    New Member

    Nov 22, 2011
    328
    14
    Code ( (Unknown Language)):
    1.  
    2. void main()
    3. {    
    4.    while(true)
    5.    {      
    6.       if(input_state(PIN_B0)==1)
    7.       {          
    8.          output_high(PIN_B7);      
    9.       }
    10.       else
    11.       {          
    12.          output_low(PIN_B7);      
    13.       }        
    14.    }  
    15. }
    16.  
    What are you compling this with?

    Can't you just read the pins directly rather than using this: input_state(PIN_B0)

    This your own array or some fucntion in the compiler?
     
  11. Gump

    Thread Starter Member

    Jun 7, 2010
    57
    1
    Ack... it seems that an edit I made to the original post last night hasn't saved... I'm using the PIC C Compiler by CCS. I cannot read the pins directly, but I shall try a different function, there are only a couple so there aren't too many to pick from and will let you know.

    Thanks.
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Have you done some debugging. Say like single stepping of the code. And some stimulus to to simulate signal on the pins. I do not know if Proteus can do this. But MPLAB can do such task.
     
  13. Gump

    Thread Starter Member

    Jun 7, 2010
    57
    1
    Yeah, it seems Proteus is quite good at that, I can step through the code and the B7 pin never goes high. I think there is an issue with the circuit more than the code...
     
  14. T.Jackson

    New Member

    Nov 22, 2011
    328
    14
    Your algorithm is certainly correct.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. if (PORTB.F0 == 1) // Compare
    4. {
    5.    PORTB.7 = 1;     // Set
    6. }
    7. else
    8. {
    9.    PORTB.7 = 0;     // Reset
    10. }
    11.  
    Same as what you have except I am directly reading / writing the port bits.
     
  15. T.Jackson

    New Member

    Nov 22, 2011
    328
    14
    Do you have a simple pull down resistor on the input pin?
     
  16. T.Jackson

    New Member

    Nov 22, 2011
    328
    14
    It gets very complex man.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. void doUser()
    4. {
    5.    /*
    6.       Procedure handles the user adjusting the time via the 2
    7.       push button tactile switches ...
    8.      
    9.       This proc renders the above proc out of scope until the
    10.       user has set all digits
    11.    */
    12.    
    13.    switch (dgToSet)
    14.    {
    15.       case 1: //              :: Setting Hours ::
    16.      
    17.          // Inc button pressed and enabled after debounce period?
    18.          if (dBounce == 0)
    19.          {
    20.             if (cInc == 0)
    21.             {
    22.                // Debounce switch contacts (ignore port for a short time)
    23.                dBounce = 1250;
    24.  
    25.                // 12 or 24 mode in play?
    26.                if (mode == 0)
    27.                {
    28.                   // (12hr mode) -- reset tens & ones if exceeded 12
    29.                   if (hrsTens == 1)
    30.                   {
    31.                      if (hrsOnes == 2)
    32.                      {
    33.                         hrsTens = 0;
    34.                         hrsOnes = 0;
    35.                      }
    36.                   }
    37.                }
    38.                else // (24hr mode) -- reset tens & ones if exceeded 24
    39.                {
    40.                   // Reset tens & ones
    41.                   if (hrsTens == 2)
    42.                   {
    43.                      if (hrsOnes == 4)
    44.                      {
    45.                         hrsTens = 0;
    46.                         hrsOnes = 0;
    47.                      }
    48.                   }
    49.                }
    50.  
    51.                // Inc ones?
    52.                if (Hrsones != 9)
    53.                {
    54.                   hrsOnes ++;
    55.                }
    56.                else // Inc tens & reset ones
    57.                {
    58.                   hrsTens ++;
    59.                   hrsOnes =0;
    60.                }
    61.             }
    62.          }
    63.  
    64.          // Call method to flash digits
    65.          flDgHrs = flashDigits(flDgHrs);
    66.          break;
    67.  
    68.       case 2: //               :: Setting Minutes ::
    69.  
    70.          // Inc button pressed and enabled after debounce period?
    71.          if (dBounce == 0)
    72.          {
    73.             if (cInc == 0)
    74.             {
    75.                // Debounce switch contacts (ignore port for a short time)
    76.                dBounce = 1250;
    77.  
    78.                // Reset tens & ones if exceeded 60
    79.                if (minTens == 5)
    80.                {
    81.                   if (minOnes == 9)
    82.                   {
    83.                      minTens = 0;
    84.                      minOnes = 0;
    85.                   }
    86.                }
    87.  
    88.                // Inc ones?
    89.                if (minOnes != 9)
    90.                {
    91.                   minOnes ++;
    92.                }
    93.                else // Inc tens & reset ones
    94.                {
    95.                   minTens ++;
    96.                   minOnes =0;
    97.                }
    98.             }
    99.          }
    100.  
    101.          // Call method to flash digits
    102.          flDgMin = flashDigits(flDgMin);
    103.          break;
    104.  
    105.       case 3: //              :: Setting Seconds ::
    106.  
    107.          // Inc button pressed and enabled after debounce period?
    108.          if (dBounce == 0)
    109.          {
    110.             if (cInc == 0)
    111.             {
    112.                // Debounce switch contacts (ignore port for a short time)
    113.                dBounce = 1250;
    114.  
    115.                // Reset tens & ones if exceeded 60
    116.                if (secTens == 5)
    117.                {
    118.                   if (secOnes == 9)
    119.                   {
    120.                      secTens = 0;
    121.                      secOnes = 0;
    122.                   }
    123.                }
    124.  
    125.                // Inc ones?
    126.                if (secOnes != 9)
    127.                {
    128.                   secOnes ++;
    129.                }
    130.                else // Inc tens & reset ones
    131.                {
    132.                   secTens ++;
    133.                   secOnes =0;
    134.                }
    135.             }
    136.          }
    137.  
    138.          // Call method to flash digits
    139.          flDgSec = flashDigits(flDgSec);
    140.          break;
    141.          
    142.       case 4: //  Exit adj time proc ...
    143.          userSet = 0;
    144.          dgToSet = 0;
    145.          break;
    146.    }
    147. }
    148.  
    149. void main()
    150. {
    151.    /*
    152.       Program entry point ... (as per usual with any C compiler)
    153.    */
    154.  
    155.   // Configuration of ports etc ...
    156.  
    157.   CMCON      = 7;       // Disable analog comparators
    158.   TRISA      = 0x0C;    // 2 inputs rest outputs
    159.   TRISB      = 0x00;    // All outputs ...
    160.   PORTA      = 0x00;    // Init port, all pins low
    161.   PORTB      = 0x00;    // Init port, all pins low
    162.   OPTION_REG = 0x84;    // assign prescaler to TMR0
    163.  
    164.   //    OPTION_REG  = %10000111            ' TMRO prescale = 256
    165.  
    166.   TMR0       =   96;    // initial TMR0 value
    167.   INTCON     = 0xA0;    // enable TMRO interrupt
    168.  
    169.   // Reset decade counter & merger to main loop below ...
    170.   mclr = 1;
    171.   mclr = 0;
    172.  
    173.   while(1)
    174.   {
    175.                         // :: Infinite program loop :: //
    176.                        
    177.      // Display current digit ...
    178.      multiplexDisplays();
    179.  
    180.      // Button allowed to be polled? / debounce period expired
    181.      if (dBounce == 0)
    182.      {
    183.         // Set button pressed?
    184.         if (cSet == 0)
    185.         {
    186.            userSet = 1;     // Flag set denoting user is adjusting time ...
    187.            dgToSet ++;      // Sec / min / hr digits in scope of being set
    188.            dBounce = 2500;  // Set debounce period
    189.            
    190.            // Reset specific variables:
    191.            
    192.            flDgHrs = 0;     // Flash hours digits
    193.            flDgMin = 0;     // ^^ Minutes
    194.            flDgSec = 0;     // ^^ Seconds
    195.         }
    196.      }
    197.      else
    198.      {
    199.         dBounce --; // Dec counter to re-enable key polling
    200.      }
    201.      
    202.      // Run clock or user is setting new time:
    203.      if (userSet == 0)
    204.      {
    205.         doTime(); // Update clock ...
    206.      }
    207.      else
    208.      {
    209.         doUser(); // User is adjusting the time
    210.      }
    211.  
    212.      // Next display digit in scope
    213.      incCounter();
    214.   }
    215. }
    216.  
     
  17. T.Jackson

    New Member

    Nov 22, 2011
    328
    14
    I don't think that I could program in ASM without sending myself bananas. Writing software is enough to send a person round the twist.
     
  18. Gump

    Thread Starter Member

    Jun 7, 2010
    57
    1
    I didn't until you mentioned it ;) the ports I am inputting to according to the PIC datasheet have internal pull-ups, but after enabling them in the compiler it hasn't made a difference.

    Yeah, see I'm not needing even a fraction of something like that.... I'll keep trying with your advice.
     
  19. T.Jackson

    New Member

    Nov 22, 2011
    328
    14
    You need pull down not pull up, because you're checking if the bit is set.

    What is your ultimate goal with what you're doing? This stuff is BS hard, takes years to get good at and is likely not to get you anywhere in life.
     
  20. T.Jackson

    New Member

    Nov 22, 2011
    328
    14
    I mean you might invent something, but if you cannot fund it, then you'll get stuff all for it.
     
Loading...