Hey FPC responders, Does anybody have a small line of example code to open a port in freepascal for AVR and immediately write a default value ?
With the code above, my relais flippers once when i put the power on the board.
Before i remove the pull-up resistors, i want to try to solve it by code.
How do you trigger the relays, with a logical low or high? Both signals can be used, it just depends on how the external relay circuit is configured.
The startup state for the port and direction registers are all 0, so basically the controller should start with all pins in a high impedance input state, which can not drive an external circuit. To change from this to an output state, you can either set DDR first, in which case the pin would sink current, or set PORT, in which case the pullup resistor would be enabled (ignoring the PUD bit for now...). This is explained in the controller's documentation, for example in the atmega328p datasheet there is a section
Switching from input to Output which explains all the possible combinations. You have to pick a sequence that does not give you an intermediate state that may trigger the relay circuit.
In your code example you first set DDRx then PORTx, so if the PORTx value is 0 to start with, it should sink current. This seem logical based on your comments, perhaps you have other code that changes the PORTx value before the code you've shown get executed?
Since you mentioned pullup resistors: after reset the controller I/O pins will be in a high impedance state, a pullup resistor will then be able to pull the pin high until the code switches the pin to output low state.