Simple microcontroller schematic (using Proteus)

Thread Starter

Gump

Joined Jun 7, 2010
61
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.
 

Attachments

tracecom

Joined Apr 16, 2010
3,944
Don't suppose anybody has any suggestions?

Thanks.
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.
 

Thread Starter

Gump

Joined Jun 7, 2010
61
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:

Rich (BB code):
 #include <16F84A.h>
#FUSES NOWDT
#FUSES LP
#FUSES PUT
#USE delay(clock=32kHz)

void main(){
   while(true){
      if(input_state(PIN_B0)==1){
         output_high(PIN_B7);
      }else{
         output_low(PIN_B7);
      }    
   }
}

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

Rich (BB code):
#include <16F84A.h>
#FUSES NOWDT
#FUSES LP
#FUSES PUT
#USE delay(clock=32kHz)

void main(){
   int1 mHigh=false;
   while(true){
      if(mHigh==true)
         output_high(PIN_B7);
      else
         output_low(PIN_B7);
      mHigh=!mHigh;
      delay_ms(1000);      
   }
}
Are you sure that the crystal is oscillating?
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.

Is it properly positioned with no signal tracks running under it? Is it on an isolated groundplane?
There's nothing other than what you see.

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.
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.
 

t06afre

Joined May 11, 2009
5,934
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?
 

Thread Starter

Gump

Joined Jun 7, 2010
61
Hello t06afre,

You circuit diagram is not anything you should try in a real world setup.
Why is this?

What are you trying to do?
Nothing more than getting the microchip to respond to an input (which never seems to arrive).

Have you looked at these examples?
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.
 

T.Jackson

Joined Nov 22, 2011
328
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.
 

Thread Starter

Gump

Joined Jun 7, 2010
61
Yeah we need to know what the project goal is man, otherwise you're just gonna drive us all bananas.
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...

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.
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.
 

T.Jackson

Joined Nov 22, 2011
328
Rich (BB code):
void main()
{    
   while(true)
   {       
      if(input_state(PIN_B0)==1)
      {          
         output_high(PIN_B7);       
      }
      else
      {          
         output_low(PIN_B7);       
      }        
   }  
}
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?
 

Thread Starter

Gump

Joined Jun 7, 2010
61
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.
 

t06afre

Joined May 11, 2009
5,934
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.
 

Thread Starter

Gump

Joined Jun 7, 2010
61
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.
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...
 

T.Jackson

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

Rich (BB code):
if (PORTB.F0 == 1) // Compare
{
   PORTB.7 = 1;     // Set
}
else
{
   PORTB.7 = 0;     // Reset
}
Same as what you have except I am directly reading / writing the port bits.
 

T.Jackson

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

Rich (BB code):
void doUser()
{
   /*
      Procedure handles the user adjusting the time via the 2
      push button tactile switches ...
      
      This proc renders the above proc out of scope until the
      user has set all digits
   */
   
   switch (dgToSet)
   {
      case 1: //              :: Setting Hours ::
      
         // Inc button pressed and enabled after debounce period?
         if (dBounce == 0)
         {
            if (cInc == 0)
            {
               // Debounce switch contacts (ignore port for a short time)
               dBounce = 1250;

               // 12 or 24 mode in play?
               if (mode == 0)
               {
                  // (12hr mode) -- reset tens & ones if exceeded 12
                  if (hrsTens == 1)
                  {
                     if (hrsOnes == 2)
                     {
                        hrsTens = 0;
                        hrsOnes = 0;
                     }
                  }
               }
               else // (24hr mode) -- reset tens & ones if exceeded 24
               {
                  // Reset tens & ones
                  if (hrsTens == 2)
                  {
                     if (hrsOnes == 4)
                     {
                        hrsTens = 0;
                        hrsOnes = 0;
                     }
                  }
               }

               // Inc ones?
               if (Hrsones != 9)
               {
                  hrsOnes ++;
               }
               else // Inc tens & reset ones
               {
                  hrsTens ++;
                  hrsOnes =0;
               }
            }
         }

         // Call method to flash digits
         flDgHrs = flashDigits(flDgHrs);
         break;

      case 2: //               :: Setting Minutes ::

         // Inc button pressed and enabled after debounce period?
         if (dBounce == 0)
         {
            if (cInc == 0)
            {
               // Debounce switch contacts (ignore port for a short time)
               dBounce = 1250;

               // Reset tens & ones if exceeded 60
               if (minTens == 5)
               {
                  if (minOnes == 9)
                  {
                     minTens = 0;
                     minOnes = 0;
                  }
               }

               // Inc ones?
               if (minOnes != 9)
               {
                  minOnes ++;
               }
               else // Inc tens & reset ones
               {
                  minTens ++;
                  minOnes =0;
               }
            }
         }

         // Call method to flash digits
         flDgMin = flashDigits(flDgMin);
         break;

      case 3: //              :: Setting Seconds ::

         // Inc button pressed and enabled after debounce period?
         if (dBounce == 0)
         {
            if (cInc == 0)
            {
               // Debounce switch contacts (ignore port for a short time)
               dBounce = 1250;

               // Reset tens & ones if exceeded 60
               if (secTens == 5)
               {
                  if (secOnes == 9)
                  {
                     secTens = 0;
                     secOnes = 0;
                  }
               }

               // Inc ones?
               if (secOnes != 9)
               {
                  secOnes ++;
               }
               else // Inc tens & reset ones
               {
                  secTens ++;
                  secOnes =0;
               }
            }
         }

         // Call method to flash digits
         flDgSec = flashDigits(flDgSec);
         break;
         
      case 4: //  Exit adj time proc ...
         userSet = 0;
         dgToSet = 0;
         break;
   }
}

void main()
{
   /*
      Program entry point ... (as per usual with any C compiler)
   */

  // Configuration of ports etc ...
  
  CMCON      = 7;       // Disable analog comparators
  TRISA      = 0x0C;    // 2 inputs rest outputs
  TRISB      = 0x00;    // All outputs ...
  PORTA      = 0x00;    // Init port, all pins low
  PORTB      = 0x00;    // Init port, all pins low
  OPTION_REG = 0x84;    // assign prescaler to TMR0
  
  //    OPTION_REG  = %10000111            ' TMRO prescale = 256
  
  TMR0       =   96;    // initial TMR0 value
  INTCON     = 0xA0;    // enable TMRO interrupt

  // Reset decade counter & merger to main loop below ...
  mclr = 1;
  mclr = 0;
  
  while(1)
  {
                        // :: Infinite program loop :: //
                       
     // Display current digit ...
     multiplexDisplays();

     // Button allowed to be polled? / debounce period expired
     if (dBounce == 0)
     {
        // Set button pressed?
        if (cSet == 0)
        {
           userSet = 1;     // Flag set denoting user is adjusting time ...
           dgToSet ++;      // Sec / min / hr digits in scope of being set
           dBounce = 2500;  // Set debounce period
           
           // Reset specific variables:
           
           flDgHrs = 0;     // Flash hours digits
           flDgMin = 0;     // ^^ Minutes
           flDgSec = 0;     // ^^ Seconds
        }
     }
     else
     {
        dBounce --; // Dec counter to re-enable key polling
     }
     
     // Run clock or user is setting new time:
     if (userSet == 0)
     {
        doTime(); // Update clock ...
     }
     else
     {
        doUser(); // User is adjusting the time
     }

     // Next display digit in scope
     incCounter();
  }
}
 

Thread Starter

Gump

Joined Jun 7, 2010
61
Do you have a simple pull down resistor on the input pin?
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.

It gets very complex man.
Yeah, see I'm not needing even a fraction of something like that.... I'll keep trying with your advice.
 

T.Jackson

Joined Nov 22, 2011
328
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.
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.
 
Top