Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

First step into microcontrollers - trouble with hardware

Status
Not open for further replies.

krissie

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

**broken link removed**

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?
 
My first question is why the flip flop in the first place?, it's not needed - nor is a transistor to feed the LED.

The PIC can quite happily feed the LED, read the switches, and provide the flip flop latching function.
 
The flip flop is because it will eventually be powered by the PC's standby line rather than the USB 5v line such that it works via the buttons while the PC is in standby... the PIC will be powered by the USB port, and only be on when the computer is on. In addition, it means less programming is required for the PIC - I simply have to tell pin 2 to send a pulse rather than toggle on or off.

The transistor powering the LED is because I intend to use a high power LED for brightness (though I note I've missed the resistor at the transistors base from the diagram).

For testing purposes, I'm using a standard LED and a 1K resistor from the JK's output.
 
Last edited:
You are making this too hard. Just provide a continual 5V for the PIC and dump the flip flops. If you need the transistor to drive more power to the LED keep it but if it is an indicator I expect you can get ones that will work

The programming for this without the relays is not difficult. People here can help with that.
 
The problem is that I need to power the LED's and switches from the standby rail of an ATX power supply.

It seems that unless I power the PIC from USB power, it fails to enumerate on the computer.
 
I think we have uncovered the real question.

How can one get a always on non USB powered PIC to be recognized by the PC when it powers up. Did you try it ?

The hub monitors the voltages on the signal lines (D+ and D-) at each of its ports. The hub has a pull-down resistor of 14.25k–24.8kW on each line. A device has a pull-up resistor of 900–1575W on D+ for a full-speed device or D- for a low-speed device.
It looks like the PC should detect the externally powered USB device as the PC powers up. I wonder if the USB device returns to the powered stated when the PC shuts down.

Another solution would to power the USB pic from the USB and use a 2nd 8 pin always powered pic to do the logic.
 
Last edited:
I'm sorry I don't seem to understand what you're saying. I have a continual 5v for testing from the USB connection.

When it comes to buliding it, I'll have 5v for the pic via USB (without which it won't enumerate - a non-USB power source seems to cause this), and a seperate continuous 5v rail for the flip flop, which will allow the LED's and switches to work in the server's standby mode. I don't understand what kind of adapter could help me here?
 
How about using an 8-pin 12F1822 device along with a $2.85 Chinese clone Nokia CA-42 cable for a "no overhead" usb-to-serial controller?

Emulating a toggle switch with standard momentary push button switches (push to toggle from on-to-off or from off-to-on) is easily accomplished in software. As is reading the state of the output.
 
I have the kit I have now, and it seems nonsensical not to use it... and likewise, it can also do it entirely on the chip... except that I need the LED's and and switches to work in standby too ... does the serial port provide power in standby? Also, it's not neatly accessible from inside the PC, but the USB headers are.

Of course... there's a second reason too...

... my hacker instinct (unused though it is - I'm no hacker! lol), wants to know why it's not working as I feel it should.
 
Last edited:
Maybe you should describe the symptoms a little more. It seems to me that if you remove USB power and then re-apply USB power that the PIC should reset and re-enumerate. Yes, no?

I admit, it's not very clear what you're trying to do. Where is this PIC controller located? Inside the Server? Inside the PC? Between the Server and the PC? Why would pressing one of the switches connected to the Flip-Flop disconnect the USB portion of the PIC from your PC?
 
Last edited:
Project:
To create a UID light that's operable by two push switches (front and back) even while the computer is in standby, which can also be operated via USB when the computer is running. The finished circuit will be mounted inside the server.

Precise symptoms, with the device fully powered by USB:

I plug the device in, and it powers up and enumerates.

I operate the device via USB with no problem, untill I press the debounced push switch linked to the JK clock on the device, and I lose the data connection to the PC - sometimes it'll fully disconnect and reconnect on it's own. Other times, it will simply stop working and I must then unplug the device and plug it back into the computer in order to re-enumerate it.
 
Last edited:
I was not thinking about the standby line when I mentioned the adapter. My intent was to delete that.

You have a few choices.


  1. Get it all working with just the single PIC you have and just switches and LED for external components. Use standby power for the PIC.
  2. Go with Mike, K8LH idea.
  3. Use your existing PIC for communication and use a 8 pin PIC as I suggested earlier.
  4. Fix your circuit.
Not sure what you UID means to you (Unit Is Down?) but to me it is User ID and you need more then a single LED for that.

Given that you need to debounce two switches and keep state info while the PC is off I like 2 and 3. With them you have the luxury of correcting logic error or making insightful changes in code. Fewer parts too.
 
Last edited:
UID in the context of servers is Unit IDentification. It's a small light, front and back of a server, that can be turned on or off from a switch either side of the server in order to find/identify the server in a rack of similar servers while working on it. I'm extending it so that it's possible to also turn the light on or off from the operating system.

The data passed between the PIC and the PC is simply an instruction to light the LED or turn it off from the PC to the PIC (a high logic pulse), and the status of the LED from the PIC to the computer.

I kind of like the fix my circuit idea, because as far as I can tell from the diagram, it should work... also, there is a slight hacker like "I want to know!" mentality about me lol... The logic is fine, in theory... and besides this problem with the push switch causing the device to unload from the computer, it works perfectly well... I just don't understand why the device is unloading from the computer.
 
Last edited:
Sorry... This... Is long.

Firstly I'd like to say, don't let my lack of posts and over all n00b-ness to "Electro-Tek-Online" fool you. I'm more or less masterful at electronic repair and engineering.

Secondly, It's probably fine but just in case you haven't tried the basics already (since no one else had suggested it). Try using a different power source/PC. Triple check all your connections and if necessary, tear it all back down to parts and try rebuilding it once or twice. And try redoing it back to the way it first was in the link you gave out and check to see if it still works that way. This is just in case you have a small wiring problem or the chip got unprogramed or damaged some how when you changed the circuit. Also, chip pin numbers "read like a clock", not "like a book". Or in other words... From pin one, count down one side then jump DIRECTLY OVER to the other side, and count back up. (These are just like 'the' most common and most often overlooked problems to have).

krissie said:
It seems that unless I power the PIC from USB power, it fails to enumerate on the computer

That definitely shouldn't be happening. You shouldn't need to power the device off the USB port if you don't want to. And based on section "17.6.2 SELF-POWER ONLY" of the datasheet (page 185) I'm thinking the code below from main.c is more or less the root of the problem. I only gave it a (really) quick look though, so I could be wrong. Someone check me.

Code:
#if defined(USE_SELF_POWER_SENSE_IO)   
tris_self_power = INPUT_PIN;                       //(which pin now???)
#endif

Also considering this from a microchip datasheet:

In order to meet compliance specifications, the USB module (and the D+ or D- pull-up resistor) should not be enabled until the host actively drives VBUS high.

All this would explain both of the problems your having.



Jon Chandler said:
Try adding a 0.1 uF bypass cap near the flip-flop. It may glitch the power when it changes.

That's possible. But If she followed the schematic on the first post to the letter, then there should already be two 100nF caps on the PIC. Which should be plenty. Especially with as short as I suspect her power connections to be. But on a similar note, try putting a 1~10k resister between !Q and the PIC. If for what ever (bad coding) reasons RA1/AN1 is high(5v) at the same time that !Q is low(0v-gnd). AND your circuit is in fact not getting enough power. It could sink too much current from that pin causing the PIC to go into brown-out-reset. It's not very likely though as I stated before. Short power leads + two 100nF filter caps = good, clean power (probably).


While your at it, you should prolly do some things to help everyone help you.

1: What is your PIC programer? I assume it is a PIC-Kit 2 just like in the project you linked too. But does it happen to be something else?

2: What software are your using to program the PIC? I assume it is MPLAB. But could it be something similar to WinPIC? (this is just so we know whether or not to give you Hex or source code)

3: What circuit board are you using? is it a proper "bread board" or "peg board" like the project you linked to? Or is it perhaps point-to-point/bird nested together?

4: What is the server and PC models you are doing this all with? (Some mother boards have a jumper for 5v-sb on the USB power rail... like mine :)

5: What other tools and equipment are you using that we should know about? Are you using an Iron that gets REALLY hot? Are you using a static strap? Things like that.


Now I think every one on this forum feels the same way when I say, "You really should do things differently". In your defense, it's more our fault than it is yours though. It's been burned in our brains for years to "optimize". And although It is true that your circuit probably can and eventually will do exactly what you want it too. It's still a whole lot of wasted hardware just to be doing such a simple task. And all that extra complexity makes it that much harder to find the root cause of your problem.

krissie said:
... my hacker instinct (unused though it is - I'm no hacker! lol), wants to know why it's not working as I feel it should.

You know, you still can figure it out even if you do your project a different way. Your current circuit will still be "broken" and still need "fixed" to give you that peace of mind.

krissie said:
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 wouldn't worry about that, the people of this forum are great at that kind of stuff. And If asked nicely, will happily help you with your project step-by-step. I would even go as far as to say. If you asked nicely, some one would probably do the coding for you. (if you would consider changing your circuit to the way they wanted.) And if your planing to keep on dealing with microcontrollers. Eventually you will have to learn how to program them your self anyway. So you may as well start now that you have a project going. It's not all that hard really. I myself started into MCU's from the electronics side of things. So I quite fully understand the "I would rather not program any thing If I don't have to" mentality. But there are just too many neat things that these little chips can do for electronics that need exploring. You won't be disappointed when you actually get some thing working good for the first time. A good beginner project is the legendary "LED mood lamp". Definitely one of my all time favorites.

My final thoughts, If it were me doing this project, I would first look for a parallel port header and try to use that. Just in case it happens to have one. (my new-ish gaming PC has a serial header on it, so you never really know). This way, I wouldn't even need a PIC, just a hand full of very common parts and a simple circuit. And the server software would be trivial and take no CPU time away from your server. It's literally like one or two lines of code. One of the easiest computer ports for the hobbyist to use IMHO.

But If I couldn't find that, I would prolly look for a serial header and use one of the many low pin count PIC's that have a serial peripheral. I would then check if that port can work with the logic levels from the PIC using just zener diodes, (It can be done) or if I needed to get a max232 or similar. The PIC would be powered off the 5v-sb wire, just as you desire. And with the lowest baud rate, and the best error correcting. It could prolly be done without the need for a crystal.

And if I absolutely had to use a USB header. I would use a lower pin count, cheaper, smaller USB PIC. Like the 18F13K50 (since I already have a ton of them.)

Sorry for rambling on for so long, I just love typing. Thanks for reading, and I hope your problem gets solved.

-Charlie: AKA ()blivion
 
Status
Not open for further replies.

Latest threads

Back
Top