#define XTAL_FREQ 20MHZ
#include <pic.h>
#include "delay.h"
#include <xc.h>
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
int ee_read(unsigned int read_address);
void running_horn();
#define RONE RA2
#define RTWO RA3
void System_init(void) {
TRISA = 0b00010011; //Making O/P and I/P for operation
PORTA = 0b00010011;
CMCON = 0X07; //Disabling Comparators
TRISB = 0b00000000;
PORTB = 0b00000000;
}
void main(void) {
System_init(); //Initialise System
while(1){
RONE=~RONE;
RTWO=~RTWO;
DelayMs(300);
}
}
#define RONE RA2
#define RTWO RA3
I presume you didn't post the real code. The only signals that are modified during program operation "left" and "right" are undefined. Respectively we can only guess how the real code might behave.
Circuitwise, the capacitors across relays coils cause high inrush current and might cause problems. You should remove it. Depending on the load switched by the relays, there may be contact arcing, possibly affecting a not well layouted circuit.
- - - Updated - - -
O.K., I see the code listing was updated in between.
Does the problem also occur if the load is unconnected?
Can you explain this one..?Try changing these lines:
to:Code:#define RONE RA2 #define RTWO RA3
#define RONE PORTA,2
#define RTWO PORTA,3
It would be better programming to avoid the '~' to invert the bits because it forces a read of the whole port to toggle one bit. It would be better to toggle bits in a variable then write them to the port.
Brian.
Then it is very likely that the problem is caused by a bad PCB layout. (Like already assumed in post#3)no the problem not occurring while removing the load..
It can cause problems in PICs without output latches, particularly PIC16F devices. The reason is the state of the port pin is read in, inverted and then written back. If for any reason the pin voltage isn't stable or it is loaded down, the wrong state will be read. What you really want to do is write 1 or 0 to the bits in the port rather than invert what is already there.Can you explain this one..?
It would be better to toggle bits in a variable then write them to the port.
Hi,
Then it is very likely that the problem is caused by a bad PCB layout. (Like already assumed in post#3)
--> Show us your PCB layout.
Klaus
Try changing these lines:
to:Code:#define RONE RA2 #define RTWO RA3
#define RONE PORTA,2
#define RTWO PORTA,3
It would be better programming to avoid the '~' to invert the bits because it forces a read of the whole port to toggle one bit. It would be better to toggle bits in a variable then write them to the port.
Brian.
No further questions. It's nearly impossible to achieve sufficient power supply bypassing with breadboard.sorry I connected everything in breadboard....
Keep load currents well away from MCU currents,
Ensure a good low impedance supply and ground around the MCU,
Fit decoupling capacitors as close as possible to VSS and VDD pins. Use say 10uF and 10nF in parallel to keep impedance low.
Make sure the wiring to the crystal is a short as possible and its loading capacitors have short wires to VSS.
Make sure the MCLR capacitor has short wires to VSS (or use internal MCLR mode).
Add 100nF ceramic capacitors across the regulator input and output pins to GND as close to the regulator as possible.
You don't show where the +12V comes from but make sure it is filtered and it's negative side is close to the power GND point.
Remove the capacitors form across the relay coils.
If any MCU pins are left disconnected, make sure they are configured as outputs or add pull-down resistors to VSS to them all.
Brian.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?