Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic 16f877a solenoid code

Status
Not open for further replies.

Solar000

Member level 2
Joined
Feb 6, 2013
Messages
49
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Greece
Activity points
1,649
Hello, i am interfacing pic 16f877a with solenoids using micro c.

I know how to control stepper motors and i thought the code would be similar
but i need some help to determine if its a hardware problem or not.

here is a simpler version of my code but its not working.They are not moving.
I have the solenoids connected to port D.

Code:
void Movement(){
TRISD = 0x00;
PORTD = 0x00;
TRISC = 0x00;
PORTC = 0x00;

//Delay_ms(20);
PORTD=0xFF;;
PORTC=0b11111111;
Delay_ms(1000);
PORTD=0b00000000;
PORTC=0b00000000;
Delay_ms(1000);
PORTD=0b11111111;
PORTC=0b11111111;
}

void main(void)
{
Movement();
}


I think i only have to set to 1 the port to activate the solenoid.
Can you tell me if the code is correct ?
Thank you.
 

hello,

show us your schematic (drawing) of wiring ..
What kind of interface do you have between PORTD Output and your solenoid ?
what is the resistor value of your selenoid ? and usual voltage ?
 

Between PORTD and solenoid i have MOSFET 100V-40A and resistor 1 k.
Solenoid is 24 V.The design of the board is for 24 V solenoids - electromagnets.

What can you say about the code? Setting port D to 1 is the way to activate the solenoid?
 

That's the way to activate an output. However, hardware is important too. Disconnect solenoids and see if the line raises. If it works and when you connect soldenoid, it stops working, then you need to look for the issue in your hardware. I also assumed your solenoids are not stepper motor coils!
 

Did you set the pins to digital?

Connect an LED right at the output of the 18F877A to eliminate possible problems with your MOSFET/drive circuitry.
 

hello,

if it works with a led connected bettwen OUTput D and 0V trough a resistor of 330 ohms (or less)
output=1 Led bright ON ?
if yes,
Specsheet data of MOSFET 100V-40A ? .. command gate level for MOSFET ON, must be < 5 volts.
and how do you connect the resistor 1 k.
Any diode accross solenoide ?
 

I haven't set pins to digital.Should i set to digital?
 

I think 1K is too large a value for your MOSFET bias. Try a much smaller one.

For the LED, especially since ytou're using it only for testing (and depending on your LED), I'd use a 1K.

And yes, its absolutely important that you connect a reverse biased diode across the solenoid.
 

Can i set port D to digital output or its only for port A ?
 

No analog input on portD
just configure it as output
TRISD=0;

Show you schematic .. and command of MOSFET..
 

Does it work if you connect a led on your PortD output , instead of the MOSFET ?

Try to add a pullup resistor on portD output like 1K
and suppress or replace your 1K serial resistor to Mosfet gate by a 100ohms or less...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top