2 SPDTrelays H-Bridge PWM help needed

Bob Champagne

New Member
Hello everybody. I have limited experience with Picaxe and programmation so need help with this project. I need to control direction and speed of a 12 volt washer wiper motor, so I built this PICAXE 08M controled H-bridge with 2 relays activated by 2n7000 mosfets and PWM by P50N06L mosfet. All mosfets are logic level. I already have etched and soldered all components on the PCB. The forward and reverse work good but I can't get no PWM.
The code I use (OK you can laugh all you want..) is:
SYMBOL ADCVALUE = W1 ;ASSIGN WORD 1
READADC10 4,ADCVALUE
PWMOUT 2, 49,ADCVALUE
GOTO MAIN
MAIN:
HIGH 0
LOW 1
PAUSE 5000
LOW 0
LOW 1
PAUSE 2000
HIGH 1
LOW 0
PAUSE 5000
LOW 0
LOW 1
PAUSE 2000
GOTO MAIN

How do I write a code that will PWM the High pin only?
I attached the general schematic as well as the actual traces on the PCB.
Thanks in advance for your help.
 

Attachments

inglewoodpete

Senior Member
The code I use (OK you can laugh all you want..) is:
How do I write a code that will PWM the High pin only?
I attached the general schematic as well as the actual traces on the PCB.
Thanks in advance for your help.
You have to start somewhere and most of us go to the comedy channnel to get a laugh.

You will find it wise to test a circuit on a breadboard before committing to a custom-made circuit board.

Your pwm command sets the frequency to 20kHz. Nothing wrong with that but the largest number you can use for duty at 20kHz is 200. So you could limit the adc reading to ReadADC 4, b2 (edited) You will find that 200 steps (0.5% each) will be more than enough.
Then add the command b2 = b2 Max 200

Back to the hardware. Remove the 08M from its socket (you did use a socket, didn't you). Using solid core wire, jumper the PWM pin 2 to +5v and likewise one of the relay driver pins. This should operate 1 of the relays and also the MOSFET. The motor should run. That will prove your hardware. After that, it will be up to the software.
 
Last edited:

Dippy

Moderator
I haven't checked through this, but when diagnosing things KEEP IT SIMPLE.

Put a fixed value PWM for testing, not an ADC value as I haven't any idea what frequency/duty you are using.

1. Are you actually getting a PWM output?
Put your 'scope on the output and check.
No scope? Got a little piezo transducer?
Check the wave shape with and without Gate connected - BREADBOARD!!!

2. Hardware.
Another problem may be the MOSFET driving.
They are NOT magic switches and need some thought as the Gate has capacitance and therefore charge has to be shoved in and sucked out.
If your frequency is low enough you may get away with it.
But at high frequencies you won't be driving the Gate hard enough; which is why the MOSFET driver chip was invented.
I'm very much out of touch with PWMOUT command now and haven't any idea of the expected Fq/Duty you may get - so it may be none of the above.

If you leave out PWMOUT can you switch the MOSFET on with a High command? Do you need to set DIR? I'm out of touch with 08Ms.

3. Breadboard.
If you are new (and it sounds like you are new) , then use BREADBOARD to prototype and experiment.
Then, when sorted, you do the PCB.

PS. Oh, he beat me to it :)
 

Bob Champagne

New Member
Thanks for your fast answers. Just some precisions before I test your suggestions. The motor turns both forward and reverse as per the values of my my initial "program". So it does get its "ground" from the mosfet. I did breadboard the PWM part and I can control the speed of the motor with the exact PWM part of my "program". Thanks again for your interest
in my problem. Bob.
 

inglewoodpete

Senior Member
I'm not sure what the problem is now. Initially you said that the PWM doesn't work but you're now saying that it does.

Are you saying that the PWM worked on the breadboard with the PICAXE, but doesn't work with the PCB?

As Dippy says, PWMing a great big MOSFET with a large gate capacitance is going to stress a PIC's output drivers. Try reducing the PWM frequency as far as you can (from memory, about 5kHz is the lower limit of the 08M) or use an external driver between the PICAXE and the MOSFET.
 
Last edited:

Bob Champagne

New Member
DIPPY:
As per your suggestion, I used a set frequency and the motor is rotating at half speed:
PWMOUT2, 249, 500. So PWM is working and I just need now to find the right code that will let me control PWM with the POT.
INGLEWOODPETE:
Funny thing is when I try to actualy write with the keyboard the command ReadADC,4,b2
I have error when verifying the syntax. But when I copy the same command from a post on the Internet no syntax error. Anyway is it how I should write the code?

ReadADC 4, b2
b2 = b2 Max 200
PWMout2, 249, b2

Thanks again.
 

Bob Champagne

New Member
Well, I finally get control over the direction, the time on, time off and speed of the motor with the following code:

SYMBOL ADCVALUE = W1 ;ASSIGN WORD 1

MAIN:
HIGH 0
LOW 1
GOSUB boucle

LOW 0
LOW 1
PWMOUT 2,OFF
PAUSE 2000

HIGH 1
LOW 0
GOSUB boucle

LOW 0
LOW 1
PWMOUT 2,OFF
PAUSE 2000
GOTO MAIN

Boucle: 'remplace la pause 5000
for b0= 0 to 9
READADC10 4,ADCVALUE
PWMOUT pwmdiv4,2, 249,ADCVALUE
pause 500
next
return

Thanks to all that helped, in particular PieM on the french forum.
 

russbow

Senior Member
Bob, just a tip for future posts. Putting your code between {code} and {/code} markers ( but using [ for { and ] for } ) makes it easier to read.

This would change
line one
line two

to ..........

Code:
line one
line two
Easier to read and scroll through

R.
 
Top