What's wrong with this simple set-up?

hamtt

Active member
Ok so I decided to start mocking up a circuit for the dash that I posted about in the other thread. Again I apologise if this is an obvious question but I'm new to this so bear with me please.

The first step was to reduce a 12v feed to 5v power the Picaxe (18M2 at the moment), so I wrote a simple program that just sent out a constant high signal on pin 18 to check if Picaxe was working properly. On the dev boad this worked fine (using a battery pack).

So on a breadboard I started working on the design and used an LM2940T-5 rectifier to drop the voltage. However I am finding that pin 18 is not giving a constant +5v (or thereabouts) out. Instead it is switching between about 4.9v and 3v. If I wire a 330ohm resistor and LED to pin 18, the LED flashes for a bit before sitching off constantly. The 5v feed to the Picaxe from the rectifier seems constant.

This is teh setup.
23441

Where have I gone wrong?
 

Hemi345

Senior Member
It sounds like the picaxe is restarting over and over. Do you have the download resistors fitted? At the very least, put a 10K resistor from Serin to ground.
 

hippy

Technical Support
Staff member
Does sound like a lack of pull-down on Download Serial In, C.4, leg 3.

It is recommended to fit a jack socket and download resistors, 10K / 22K, to all circuits - Then you can easily check if a PICAXE is running, and easily download code to test input as outputs as you build up the circuit using SERTXD to see what's going on ...
Code:
#Picaxe 18M2
#Terminal 4800
#No_Data
Do
  SerTxd( "I'm alive!", CR, LF )
  Pause 1000
Loop
 

hamtt

Active member
It sounds like the picaxe is restarting over and over. Do you have the download resistors fitted? At the very least, put a 10K resistor from Serin to ground.
Adding the 10k resistor from Serin to ground seems to fix the issue, but now I'm finding after about a minute the test LED is going off and this time the 5v-in to the Picaxe is dropping, after a while it comes back up again. Could the rectifier be getting too hot (is only slightly warm to touch) or tripping up somehow?
 

hippy

Technical Support
Staff member
It does sound like the regulator is cutting out but that's surprising. The regulator is rated for 1A and the PICAXE plus LED should only be drawing tens of milliamps.

Normally, when over-current or thermal cut-out kicks-in a regulator will be 'burning hot'.

It could be that there's a wiring issue. Might be worth posting a photo of your breadboard setup and the code you are using.
 

Buzby

Senior Member
For your breadboard test rig, what is the 12v supply ?. Is it a car battery, a wall plug PSU, or something else ?.
 

hamtt

Active member
It was a wall-plug type 12v 2a psu. I found the issue was with this power supply for some reason. I tried a different 5.5v power supply lying around and with that I didn't have an issue. So today from work I picked up another 12v 1.5a power supply and I'm not having the issue with this one.

Strange. I found the power supply itself was actually tripping up and then when it reset, it would power up the circuit again. I wonder if I need to insert a diode at the beginning of the circuit to protect the PSU. Should there be anything coming back from the rectifier?

And now on to the second bit of the circuit, I need to amplify the 5v pwm pin to 12v. I'll have a go with a transistor and a P-channel mosfet. Do I need to insert a resistor berween the pwm pin of the picaxe and the transistor or P-channel mosfet?
 

inglewoodpete

Senior Member
Some switch-mode power supplies seem to want a minimum load to work properly. Perhaps this was the cause of your problem.

You will need a resistor (try 1k0 to 2k2) between the PICAXE pin and the base of the NPN driver transistor, otherwise you may damage the base-emitter junction of the transistor.

At the very least, you will need a pull-up resistor between the P-channel MOSFET's gate and the +12v rail. Don't put a resistor between the NPN's collector and the gate as this will slow the MOSFET's switching speed.

Finally, run the PWM at the lowest frequency that you can (I suggest ~500Hz), otherwise you may find the apparent output of the MOSFET to be non-linear. Without a dedicated MOSFET driver, the relatively high capacitance of the MOSFET's gate will result in the MOSFET switching 'on' and 'off' quite slowly. Slow switching leaves the MOSFET in its resistive state, rather than 'on' or 'off', for a significant part of the PWM cycle. This results in heating of the MOSFET rather than efficiently transferring energy to the load. Using a low PWM frequency reduces the number of 'on-off-on' transitions per time period, resulting in less waste heat.
 

hamtt

Active member
OK so I have a dilemma now which I could appreciate some input with.

I wired up the actual 8 switches with the LED's in them directly to the picaxe 5v pin and tested the PWM function and it seems to work fine and is adequate on the 5v direct from Picaxe, so I could do away with having to use a P-channel mosfet to convert to 12v. However my only concern is when the switch shorts, I will be jumping 12v on to the same line so I will be mixing 5v and 12v on same circuit.

The alternative is to stick to original plan and get the PWM'd 5v upped to a 12v PWM with a P-channel mosfet.

Is there any advantage or disadvantage with either method (besides the obvious less components) and if method 1 is ok then how do I protect the 5v picaxe pin from the 12v shunt when the switch shorts? Will a simple diode do?
 

hippy

Technical Support
Staff member
^ "What he said"

From the earlier thread it seems to me there are four ways your switches should be wired up -
Code:
      12V --.--          .-------.
            |            |       |
            `--|>|---.   |  LED  |
                     }---|--|>|--|-----.
PICAXE PWM >---|>|---'   |       |     |
                         |       |     |
                         |   /O--|-    |
       5V >--------------|--O    |     |
                         |    O--|--.  |
                         `-------'  |  |
PICAXE IN <--.----------------------'  |
            .|.                        |
            |_| 10K                    |
             |                         |
PICAXE 0V ---^-------------------------^-- 0V
Code:
       12V --.--         .-------.
             |           |       |
             }--|>|--.   |  LED  |
             |        }--|--|>|--|-----.
PICAXE PWM >-|--|>|--'   |       |     |
             |           |       |     |
             |           |   /O--|-    |
             `-----------|--O    |     |
                         |    O--|--.  |
                  ___    `-------'  |  |
PICAXE IN <--.---|___|--------------'  |
            .|.   22K                  |
            |_|                        |
             |  10K                    |
PICAXE 0V ---^-------------------------^-- 0V
Code:
      12V --.--          .-------.
            |            |       |
            |            |   /O--|--
            }------------|--O    |
            |            |    O--|--.---> 12V Switched
            |            |       |  |
            `--|>|---.   |  LED  |  |
                     }---|--|>|--|--|--.
PICAXE PWM >---|>|---'   |       |  |  |
                  ___    `-------'  |  |
PICAXE IN <--.---|___|--------------'  |
            .|.   22K                  |
            |_|                        |
             |  10K                    |
PICAXE 0V ---^-------------------------^-- 0V
Code:
      12V --.--          .-------.
            |            |       |
            |            |   /O--|--
            `------------|--O    |
                         |    O--|--.---> 12V Switched
                         |       |  |
PICAXE PWM >---|>|---.   |  LED  |  |
                     }---|--|>|--|--|--.
            .--|>|---'   |       |  |  |
            |            `-------'  |  |
            `-----------------------{  |
                  ___               |  |
PICAXE IN <--.---|___|--------------'  |
            .|.   22K                  |
            |_|                        |
             |  10K                    |
PICAXE 0V ---^-------------------------^-- 0V
Which to use would depend on whether the 12V is to the battery, or comes from a 12V signal line such as to an indicator bulb, whether the LED illuminates all the time when that 12V is present or only when the button is pushed.

Different switches may need to be wired differently.
 
Top