I am using an Atmega328P on a custom PCB but the output pins are showing 0V even though I set them to High in the code. To test if the Atmega itself was working, I put the Atmega on an Arduino Uno board and the VCC and output pin shows similar voltages. What could be causing this and is there a way to fix it?
What could be causing it? Pretty much anything at this point. You haven't shown us your sketch, your schematic, your PCB, anything. We've got absolutely nothing upon which to even offer an educated guess.
Post the code, using code tags.
#include <cppQueue.h>
#define FS1_PIN 3
#define FS2_PIN 4
#define FS3_PIN 5
#define FS4_PIN 6
#define IN1_PIN 8
#define IN2_PIN 9
#define ENABLE_PIN 10
struct SwitchState {
bool ENABLE;
bool IN1;
bool IN2;
unsigned long startTime;
int floatSwitch;
};
cppQueue stateQueue(sizeof(SwitchState), 4, FIFO);
const unsigned long stateDuration = 1000;
void setup() {
Serial.begin(9600);
pinMode(FS1_PIN, INPUT);
pinMode(FS2_PIN, INPUT);
pinMode(FS3_PIN, INPUT);
pinMode(FS4_PIN, INPUT);
pinMode(IN1_PIN, OUTPUT);
pinMode(IN2_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
}
void loop() {
bool fs1Active = digitalRead(FS1_PIN);
bool fs2Active = digitalRead(FS2_PIN);
bool fs3Active = digitalRead(FS3_PIN);
bool fs4Active = digitalRead(FS4_PIN);
if (fs1Active) {
SwitchState state = {HIGH, LOW, LOW, millis(), 1};
if (!stateQueue.push(&state)) {
Serial.println("Queue is full, could not push FS1 state.");
}
}
if (fs2Active) {
SwitchState state = {HIGH, LOW, HIGH, millis(), 2};
if (!stateQueue.push(&state)) {
Serial.println("Queue is full, could not push FS2 state.");
}
}
if (fs3Active) {
SwitchState state = {HIGH, HIGH, LOW, millis(), 3};
if (!stateQueue.push(&state)) {
Serial.println("Queue is full, could not push FS3 state.");
}
}
if (fs4Active) {
SwitchState state = {HIGH, HIGH, HIGH, millis(), 4};
if (!stateQueue.push(&state)) {
Serial.println("Queue is full, could not push FS4 state.");
}
}
processQueue();
}
void processQueue() {
if (stateQueue.isEmpty()) {
digitalWrite(IN1_PIN, LOW);
digitalWrite(IN2_PIN, LOW);
digitalWrite(ENABLE_PIN, LOW);
} else {
SwitchState currentState;
if (stateQueue.peek(¤tState)) {
unsigned long elapsedTime = millis() - currentState.startTime;
if (elapsedTime >= stateDuration) {
stateQueue.pop(¤tState); // Correctly pop the state
} else {
digitalWrite(IN1_PIN, currentState.IN1);
digitalWrite(IN2_PIN, currentState.IN2);
digitalWrite(ENABLE_PIN, currentState.ENABLE);
}
} else {
Serial.println("Failed to peek at the queue.");
}
}
}
I suggest to test the output pin functions with a simple program like this:
#define IN1_PIN 8
#define IN2_PIN 9
#define ENABLE_PIN 10
void setup() {
pinMode(IN1_PIN, OUTPUT);
pinMode(IN2_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
digitalWrite(IN1_PIN, 1);
digitalWrite(IN2_PIN, 1);
digitalWrite(ENABLE_PIN, 1);
delay(5000);
digitalWrite(IN1_PIN, 0);
digitalWrite(IN2_PIN, 0);
digitalWrite(ENABLE_PIN, 0);
}
void loop(){}
What are those pins supposed to do, given that they are connected to 74LS11 chips?
How are your switches wired? I see a FLOATIN connector and a FLOATGND connector, which makes me think they might be grounded when closed. You have declared their pins as INPUTs, so if that's the configuration, unless you've got pullup resistors they're going to be floating when the switches are open. So they could read HIGH or LOW.
Secondly, as written, your code is going to be constantly pushing states into the queue as long as any switch reads HIGH. Is that by intention? Or is the intention to push one new state when the switch changes from open to closed (i.e. an event rather than a state)?
If we had some idea what it was you were trying to achieve, this process would be a whole lot easier...
I was trying to use the 3 output pins to control the outputs of the logic gates, which would then control a 4 channel relay.
The Arduino can do logic, so the 74LS11 chips are not needed. Furthermore, they are TTL chips, and the low V(OH) output voltage is not guaranteed to meet specs for 5V CMOS logic.
But that is beside the point, as there are likely to be one or more problems with the wiring and code you are using to test the outputs.
I am trying to use 4 float switches to control a 4 channel relay which opens and closes their respective solenoid valves.
The idea behind the queue was so that in the event that there happens to be two or more float switches were active at the same time, the first switch would be processed first and their corresponding output pin state combination would be used first for a short period, before the next float switch gets processed to avoid conflicting output pin states.
I am sorry about the confusing code.
Event timing and ordering requirements can very easily be handled by code, which is much easier to change than hardwired logic, especially with obsolete TTL logic chips incompatible with modern MCU voltage levels.
Quite so. The whole concept of taking 3 outputs from a controller to make 4 switching outputs is very silly indeed.
@jcdb4 the only sensible thing to do is start over with your project. Forget about this PCB you have with the logic gates.
Does this mean you also get 0V output with the uC mounted on the UNO board, or you get similar voltages as with the original uC that came with the UNO? I.e. does the problem follow the uC chip, or does it stick with the board it's mounted on?
Anyway, when redesigning your PCB, I'd make a couple of changes:"
- remove the AND ports, obviously
- group the connectors per connected device, not per net; this will be less confusing and will also tidy up your external wiring. So group the 4 wires to a single relay on a single header/connector, etc.
- Include a provision to program the controller so you don't have to remove the uC every time you need to program it (you'll end up bending and ultimately breaking some pins off of the chip unless you use a ZIF socket). So throw in an SPI header and also make a header for a serial programmer (TX + RX + RST) so you can easily use the Arduino IDE to program your board using a Serial/UART bridge ('FTDI cable').
- Fix the problem of the missing decoupling capacitors on the uC. They should also be added to the logic chips, but since you'll be ditching those anyway, it's moot.
The next version of your board can also fix the overly thin power supply traces and the unnecessarily narrow spacings. Throw in a ground plane since you're paying for the copper anyway; might as well leave it on the board, too. There are quite a few fairly recent threads of people asking for PCB layout advice, showing their initial attempts up to the final design; I'd have a close look at those so you can incorporate the advice given there in your project.
Why would you add all that extra complexity and extra components to save a single atmega output pin, when there are so many unused and available? What feature of 74LS11 made that worthwhile, in your understanding?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.


