Maker Pro
Maker Pro

Microcontroller controlled by pushbutton for LED flashlight

The problem with MPLAPXIDE was that there was no compiler selected (thanks Dan). Here is what I did. I followed Supercap"s instructions (thanks again Dan) and successfully built a new project, copying and pasting Adam's asm file into the new project. I then went and edited the asm file and replaced all "GPIO, 0" to "GPIO, 2". I then successfully programmed and verified the PIC. With the power supply set to 4vdc, operation is as follows:

1) Upon applying power to the circuit, the LED starts flashing on/off very rapidly. I don't have a scope, but I would guess a rate of 100hz or so.
2) During this flashing, the power supply to the PIC is 1.7vdc. I would assume my meter (Fluke 87) is averaging and the actual voltage is approximately 3.6vdc, cycling with the LED. This tells me that the capacitor is not keeping the PIC alive and it is shutting down and re-starting as fast as it can.
3) Pressing the switch for less than 500ms momentarily stops the flashing, then it continues when switch is released.
4) Pressing the switch for more than 500ms permanently stops the flashing. At this point, the switch does nothing, regardless of how long it is pressed. The only way to get the output to come back on is to remove power to the circuit and re-apply. The flashing then starts all over again.
5) When the LED shuts off after a long switch press, there is 3.65vdc powering the PIC.

This is all I can do here. I use these computers to run my business and cannot open them up to remote access.
 
Last edited:
Hop,
I can send you a populated board, ready to practice on. You would still need to get a genuine Microchip USB programming thingy, but this would save you some time.
 
Last edited:
The problem with MPLAPXIDE was that there was no compiler selected (thanks Dan). Here is what I did. I followed Supercap"s instructions (thanks again Dan) and successfully built a new project, copying and pasting Adam's asm file into the new project. I then went and edited the asm file and replaced all "GPIO, 0" to "GPIO, 2". I then successfully programmed and verified the PIC. With the power supply set to 4vdc, operation is as follows:

1) Upon applying power to the circuit, the LED starts flashing on/off very rapidly. I don't have a scope, but I would guess a rate of 100hz or so.
2) During this flashing, the power supply to the PIC is 1.7vdc. I would assume my meter (Fluke 87) is averaging and the actual voltage is approximately 3.6vdc, cycling with the LED. This tells me that the capacitor is not keeping the PIC alive and it is shutting down and re-starting as fast as it can.
3) Pressing the switch for less than 500ms momentarily stops the flashing, then it continues when switch is released.
4) Pressing the switch for more than 500ms permanently stops the flashing. At this point, the switch does nothing, regardless of how long it is pressed. The only way to get the output to come back on is to remove power to the circuit and re-apply. The flashing then starts all over again.
5) When the LED shuts off after a long switch press, there is 3.65vdc powering the PIC.

This is all I can do here. I use these computers to run my business and cannot open them up to remote access.

1.7 volts is below it's operating voltage. It should flash once on power up until you press the swich. If I have time tommorrow I will try a video to show you it working my end just so you dont think I am a complete numpty. :)

oh one thing it might be is I used a pull up 10K resistor on Mclr reset line. In the code at the top is say MCLRE_ON you could try changing it to off. I always like to use a pull up resistor. Not a great fan of internal pull ups.

Edit, thiis might not be the problem, it might be we need a bigger capacitor.

Adam
 
Last edited:
I cannot play along if we are working off different schematics. 5vdc supply gave the same results, except the averaged voltage supplying the pic while flashing was 1.85vdc and 4.77 while the LED is off.
 
OK, I changed MCLRE_ON to MCLRE_OFF. Operation is the same. Here is the asm file that is programmed on the PIC now...
 

Attachments

  • Main.zip
    1.9 KB · Views: 56
I cannot play along if we are working off different schematics. 5vdc supply gave the same results, except the averaged voltage supplying the pic while flashing was 1.85vdc and 4.77 while the LED is off.
Its not about playing along Jeff. If its powered from 5 Volts then the circuit should run without the need for the cap. It about trying to find out the problem.
Thanks Adam
 

hevans1944

Hop - AC8NS
Hop,
I can send you a populated board, ready to practice on. You would still need to get a genuine Microchip USB programming thingy, but this would save you some time.
Thank you! I will send you a PM with my address and telephone number when I am ready for that.

Meanwhile, Adam seems to have the best opportunity now to figure out what is wrong since I haven't read his code yet. I do have the test equipment (oscilloscope, five-digit VOM, etc.) to probe a little more deeply into the problem, but it appears to be related to getting enough charge onto the capacitor to sustain the PIC and prevent an automagical brown-out reset when the LED in the flashlight is turned on, i.e., when the MOSFET switch is conducting.

Adam may have to tweak the duty cycle, decrease the oscillation period (make it run faster), or farkle with the capacitance value AND put the PIC to sleep most of the time to minimize the PIC power drain. In fact, if possible, sleep mode should be the predominant PIC mode, waking up only when there is a button-press or a watchdog time-out signaling its time to renew the charge on the capacitor. I assume the flashlight will spend most of its time in a drawer instead of in use, so it is important to keep the load presented by the PIC down in the microampere or even nanoampere range (if that is possible). The last thing you need is to pick up the flashlight and discover the PIC has drained the battery over the course of a few months. That's probably not likely, given it is "sipping" through a 300 ohm resistor across the LED to charge the capacitor when idle, but I would like to know how much "idle" current it draws when the flashlight is off. As soon as I get my "stuff" to play with I will measure this.

I agree that messin' with the supply voltage is not a good idea. If anything, the PIC somehow needs to accommodate a "run down" flashlight battery! I hate a flashlight that needs to be banged on a table to restore brightness... mainly because that almost never works.

BTW, my interest in PICs is not entirely altruistic. I am working on a wristband comuncations concept that allows the wearer to "personalize" small electrical appliances. The Arduino Uno with XBee modules that I am working with now is just for "proof of concept." A PIC with some add-on RF or NFC capability may be more appropriate down the road.
 
Thanks Hop. I am working on the sleep side of it. I dont know if you can wake up the PIC with two stimulus, watch dog and port change. The thing is it needs to turn off when the button is pressed, so if its waiting for the watch dog to wake up it wont respond to the switch.

If its too long in sleep it may appear to sluggish to wake up and turn off. Its catch 22. Thing is the power is so low anyway I am thinking of not putting it to sleep and just increase the cap size.I might change the PIC with one I can run in 32KHz mode reducing the power further. But for now it would be good just to get it running with 5 Volts.

We could try powering the PIC from the programmer. Set the programmer to VDD on and then release from reset.

Adam
 
Its not about playing along Jeff. If its powered from 5 Volts then the circuit should run without the need for the cap. It about trying to find out the problem.
Thanks Adam
By "playing along", I meant being able to troubleshoot along side you. This micro programming is extremely confusing to me, especially when I have a CNC lathe and mill running literally 3 feet behind me and you're expecting me to get the same results as you, even though you are using different pin assignments, different components, more components and a supply voltage that will not be available. I want to help as much as I can, but I keep getting more confused.
 
Last edited:
Ok I thought you changed the pin out, was that all you found wrong? Jeff dont get stressed let me look at it tommorow, its late over here I am off to bed now. But you could try it leaving your programmer connected and look in the programmer menu in MPLAB and see if there is an option to turn VDD on. There should also be an option to release from reset. It should then run.
Adam
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
The interfaces between design and reality, and between hardware and software can be quite frustrating. One of the reasons for a big prototype board is that it allows you to "bodge in" additional components or cut and rewire traces.

Jeff, I imagine you don't have spare components laying around so it may be best for Adam, Hop, and others to brainstorm a bit.

When passing along suggestions to you it would be best if we are careful to be explicit with what we want you (Jeff) to do so as not to waste your time or cause unnecessary frustration.

When Adam asked that you apply 5V direct to the PIC, I get the feeling that everyone here except you understood exactly what he meant. That's not your fault, it's ours. I think sometimes we get so used to talking in shorthand to people skilled in electronics that we start to do the same too quickly with people like yourself who picks things up quickly and produces high quality work.

What we should have explained (perhaps) is exactly where we wanted you to connect the positive and negative leads of your power supply, the load, etc.

From the results that you posted, it seems that for the possible interpretations the results were either expected or indicative of a major problem.

My feeling, echoed by others earlier, is that the most probable cause is that the capacitor value is too low or that it has insufficient time to charge sufficiently. I think the guys are on to this so I imagine we'll see either a change in the software or a hardware change soon.

Don't stress about the time anyone puts into this. I can fairly confidently say that this is what most of us call "fun". Even if that were not the case, we have even more reasons to help you than usual.
 
Last edited:
Thanks Steve, very well said... Just for the record, I was never asked to apply 5v directly to the PIC. I would have done so if asked. I was asked to "power the PCB from 5 volts" and that is what I did.

If you can power the PCB from 5 volts and see if that works.
Adam
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Exactly! The difference between what you were told and what I interpreted it to mean!

Adam goes on to say that this will mean no cap is needed. In order for this to be true the mosfet can't be allowed to short the power supply. For that to be true the connection for the positive end of the power supply must be on the cathode of the isolating diode.

So what I believe to be the correct interpretation requires that you understand the operation of the circuit and the problem trying to be solved, and then to do something different to the literal meaning of the words.

And this is where we need to be careful.
 
Top