Maker Pro
Maker Pro

First step into microcontrollers - trouble with hardware

Krissie

Nov 23, 2010
8
Joined
Nov 23, 2010
Messages
8
I once took a GCSE class in electronics back about 12 years ago, though I've forgotten a lot now, and am just getting back into it. Im working on a project to create a UID light or a rackable server I'm building... it needs to to the following:

Light or turn off an LED when a push button is pressed at the back of the server.
Light or turn off an LED when a push button is pressed at the front of the server.
Light or turn off an LED when told to do so from within the operating system on the server.

Due to availability and a desire for tidyness, I've opted to use a USB interface with the computer, connecting it to the USB headers on the mainboard. The USB port also supplies a nicely regulated power source.

I've never done this before, and so while searching around, I stumbled on a tutorial on creating a PIC based USB device that seemed almost ideal for my little project, using a 40 pin PIC 18f4550 - [link here]. I successfully built the device on a breadboard according the the given schematic, and successfully programmed it using the software provided. The device successfully connected to the PC, and running the proided executable, I was able to switch its LED on or off (or to be more acurate, toggle pin two between 5v and 0v from the computer), and I was able to read the value of a pushswitch at pin 3 (5v for open, and 0v for closed).

Programming is not my greatest skill (far from it!), and so I opted to bring this a step closer to what I wanted with the hardware rather than the firmware. I used a JK flip flop (which this forum helped me to get working - thank you) to divide its clock by two, using a switch for a clock pulse - so creating a push on/push off switch. I also connected pin 2 of the microcontroller to the clock of the flipflop via a diode so that the flip flop could be operated from either a push switch or from the computer. The flip flop's !Q output (which is either 5v or 0v... in theory) was connected back to Pin 3 of the PIC, replacing the switch...

fullcircuitsmall.jpg


The microcontroller was successfully able to operate the JK flip flop on instruction from the computer to send a clock pulse from its pin 2, and was successfully able to read the LED state on the flip flop using the !Q input of the flipflop connected to the PIC's pin 3, which was reported back to the computer via USB... so far so good.

... my problem is that when I operate one of the push to make switch on the flip flop, the device unloads from the computer, and computer control is no longer possible... though the flip flop continues to work via the push switch input. Unplugging the USB connection and plugging it back in causes the device to be recognised once more, and makes computer control of the device once more possible ... untill one of the physical push switches is operated again.

Does anybody understand why?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Firstly, I don't understand why.

But here are some tips for better and/or simpler design.

1) remove the JK flip flop and drive the LED/transistor direct from the PIC.
2) have your switches connected to a PIC input (with a pull-down resistor). You can do debouncing in software.

This will save you a lot of hardware complexity at the expense of software complexity. But it's easier to change the software than the hardware.

It is entirely possible that the problem you're having is software related. If your code is reasonably short we may be able to spot something.
 

Krissie

Nov 23, 2010
8
Joined
Nov 23, 2010
Messages
8
Unfortunately, the flip flop is required. It will be powered by the standby line of the server's ATX power supply so that it works while the PC is in standby. The PIC will be USB powered to interface with the flipflop once the computer is turned on.
 
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
That's a good reason. In that case do what I suggest, but drive the clock from only the uC.

You may have to guard against problems caused when the uC is de-powered and the JK flip flop has power. The input protection circuitry could provide a low impedance path to earth in this case.

edit: series resistors may be all you require.
 

Krissie

Nov 23, 2010
8
Joined
Nov 23, 2010
Messages
8
The problem with driving the clock only from the uC is that when it's unpowered, the JK can't be toggled. Much as I'd like to power the uC from the standby rail also, it seems that unless USB power is used, the device doesn't enumerate when connected to the computer.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
OK, the problem I had originally (that I didn't explain) is that your debouncing will cause a slow rise/fall time. I believe that clock inputs tend to prefer fast rise and fall times.

I don't think this is a cause of your current problem though.

My concern is that the lockup is happening due to a software error. Try changing your software so that all it does is reports the status, or disconnect the pic output that clocks the flip-flop and see if that makes any difference. (both tests would be worthwhile)
 
Top