Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] 16f690 to AND Gate or any other PORT ........

Not open for further replies.


Newbie level 3
Sep 27, 2013
Reaction score
Trophy points
Activity points
I am coding a PWM to a H-Bridge using a shift register. The code to the shift register works but when I look at my PWM, it appears that a logic gate is pulling down the signal on PORTC.RC3. I remove the wire from PORTC.RC3 to a logic gate, the clock signal is fine. Place the wire on the logic gate, the clock starts and stops. It appears that the signal on PORTC.RC3 is being loaded down by the logic gate.
Do I need a pull-up resistor on a transistor to drive the logic gate using a 16f690? I have swapped out the logic gate with a new gate.

// 16f690
// 74HC08
// H-Bridge
#include "shift_data_in.h"        // This clocks in data to the shift register
#include "output_info.h"          // This outputs the data on the shift register 

void main(){
   CM1CON0.C1ON = 0x00;           // disable comparitor
   CM2CON0.C2ON = 0x00;           // disable the other comparator

   TRISC   = 0x00;                // Set all of PORTC as I/O
   PORTC = 0;                      // Starts the shift register at zero


// Turn right motor on
// Shift register info passing
        DS_Data_IN(right_FW);                  // Sends info over to shift register
        output_data();                             // Outputs the data in the shift register

// My PWM worked using the libraries
// as well as coding the PWM
// This is just for testing purposes      

        for(y_in = 0; y_in <= 1000; ++y_in){
            RC3_bit = 1;
            RC3_bit = 0;
   }  // END WHILE
}  // END MAIN

Schematic H-Driver.png

I've not used that device myself but I do know the Microchip range quite well.
One thing that stands out is that RC3 has analog functionality which you are not turning off (via the ANSEL register). The analog functionality makes the port bit read as '0'. This device only has a PORT register (and not a LAT register) and so is open to the RWM problem and this may be what is impacting you, depending on the actual code the compiler generates in response to the "RC3_bit = 1;" and similar instructions.
The device itself is certainly capable of driving a logic gate input pin. Therefore I'd also check that there is no short or other physical construction issue with the connection to the logic gate.
By the sound of it, you are using a breadboard for the construction (as you can remove and replace wires with apparent ease). Just be careful with those as it is very easy to get shorts between lines and the lines tend to have a lot of capacitance with the adjacent lines. the capacitance should not be an issue unless you are getting in to higher frequencies.
Also make sure that the MCU has stable power and ground connections and all bypass capacitors are in place.
You don't show the config settings so I assure that you have set the device to use an internal oscillator as there does not appear to be an external clock source in the schematic.
Would you believe I took the ANSEL off because I was not using PORTA, and yes, I just read that PORTC does have an analog function.
As for setting the fuses, I am using MIKROC and setting the fuses is made very simple. The PWM on RC3 was just a test. I could not figure out why I could not drive a simple AND gate. (Its easy!) Anyway, before I read your post, I went to Radio Shack, spent triple the price and purchased a 555 to create my PWM. At this time, I just require one speed.

I will code the ANSEL and give a reply back. Thank you for your very good reply.


By the way, my work requires a Wayne Kerr LCR and believe it or not, I have test a bread board from 60Hz to 3GHz.

Adding the ANSEL seemed to work.

   CM1CON0.C1ON = 0x00;           // disable comparitor
   CM2CON0.C2ON = 0x00;           // disable the other comparator
   ANSEL        = 0x00;                // Set as Digital
   ANSELH      = 0x00;                // Set as Digital
   TRISC        = 0x00;                // Set all of PORTC as I/O
   PORTC       = 0x00;                // Set to Zero

Not open for further replies.

Part and Inventory Search

Welcome to