after successfully testing my circuit on arduino and breadboard, i decided to realise it on a through hole pcb using atmega 328p, it basically takes value from sensor and depending on that value it controls the different output pins, i have set the fuses for it to run at 1 mhz for low power operation, initially the pcb prototype worked fine but within 2-3 days it started acting weirdly and its output started switching randomly irrespective of its adc value, to resolve it i used a different chip attiny 45 but it too faced the same problem and then i took out the chip from the pcb to test it in isolation without any adc input, even then its outputs were randomly toggling, i have been hitting my head over it for the past two months please help me out, circuit is fine something is either wrong with my programming or the chip's fuses, fuses are set at default other than the clock fuse. i have attached my code, please help me out guys
If you don't have anything connected to the ADC pin, the pin will pick up electromagnetic noise from the environment and you'll get random readings. Google "floating pin"
I would suspect a bad connection / broken wire from the analog input resulting in the ADC pin floating, giving you random values.
Hi,
Welcome to the forum.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks.. Tom..
the circuit doesnt matter because the chip's output are toggling when in isolation same as when it is plugged in the circuit, so the problem is in the programming or the fuses or i am missing out on some chips feature. i have tried setting the adc's reference both internally and externally, it doesnt really make any difference the pins keep toggling, i have tried decoupling capacitors, increasing supply voltage, please help me out, when plugged in the adc pin isnt floating still the problem is there.
int const numReadings = 5;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int taverage = 0; // the average
void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
analogReference(INTERNAL);
}
void loop() {
digitalWrite(0, HIGH);
int y = analogRead(1);
total = total - readings[readIndex];
readings[readIndex] = y;
total = total + readings[readIndex];
readIndex = readIndex + 1;
if (readIndex >= numReadings)
{
readIndex = 0;
}
int x = total / numReadings;
{if ( x >= 173)
{digitalWrite(1, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
}
else
{digitalWrite(1, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
delay(2);
}
}
}
Hi,
the circuit doesnt matter because the chip's output are toggling when in isolation same as when it is plugged in the circuit,
What does "in isolation" mean?
We need to see your circuit diagram so we can see what is connected to your controller.
Your input and output pins in your code are useless to identify their usage.
Are you using pin0 and pin1 on the 328 as I/O, they are the programming pins and should be avoided.
What is the sensor and what are the outputs?
How are you powering your project.
Tom...
in isolation means the uC is powered on a breadboard without any analog input, just a cap at the analog input pin to ground, the code is for an ATTINY 45 not of 328p. the thing is the uC output pins are toggling even when there is no analog input and also when there is an analog input so the rest of the circuit isnt a problem, i have powered the ATTINY 45 with two double AA batteries ie around 3V and it runs at 1 MHZ so insufficient power i dont think should be a problem and i checked with a multimeter i am getting an offset of around 50mv at the adc pin.
What sensor have you connected to pin A1 (physical pin 7 of the ATTiny45) ?
It should have an impedance of max 10K according to the data sheet.
If you have nothing connected you will get, as has been explained, random results.
If you pull pin A1 high, analogRead will return a stable value of 1024.
If you pull pin A1 low , analogRead will return a atable value of 0.
Does your layout and pin usage correspond with this?:
Hi,
KAUSTUBHT:
in isolation means the uC is powered on a breadboard without any analog input, just a cap at the analog input pin to ground, the code is for an ATTINY 45 not of 328p. the thing is the uC output pins are toggling even when there is no analog input and also when there is an analog input so the rest of the circuit isnt a problem,
Go back and read post #1, you cannot leave an active analog input open circuit, even with a cap to ground, it is still open circuit and floating.
Gnd the analog input witha link if you want no input signal.
Try it.......
If you replace you "sensor"with a potentiometer to give you an input from 0V to 5V, do you get stable results then.
We need to see your circuit diagram so we can see what is connected to your controller.
Your input and output pins in your code are useless to identify their usage.
Please what is the sensor and what are the outputs?
Tom....
the analog input A1 is connected to a mini bridge based pressure sensor via an instrumentation amplifier INA 122 with its gain set at 5.
Hi,
- Have to replaced the sensor on the input with a potentiometer and tested the code?
- Have you tried connecting the input to gnd to see if the problem still exists?
Any bridge signal will be noisy, a bridge is used to detect small changes in a circuit parameter, however it is inherently susceptible to noise, not just from the detector, but the amplification system and the surrounding electrical noise.
Do you have access to an oscilloscope so you can monitor your input signal?
Thanks.. Tom...
@KAUSTUBHT - Your project worked at first for a couple of days, therefore their is sod all wrong with the software. Software dosn't just develop faults. Your problem is crappy hardware, but you seem reluctant to face reality.
So if you want help then post your schematic, don't keep saying you have tried this and that and it didin't work, like pulling more rabbits out of a hat and drip feeding us with information. Basically you have something wrong and we are itching to tell you what, but unless we can see what you have then you are just jerking us about. We are on reply #10 here and you are no closer to finding out where you screwed up than you were at the initial post.
i have tried manipulating the analog input port with a potentiometer still the random toggling persists but when i ground the input pin then the pins dont toggle, only the pin that is supposed to be high at 0 input is high.
Hi,
KAUSTUBHT:
i have tried manipulating the analog input port with a potentiometer still the random toggling persists but when i ground the input pin then the pins dont toggle, only the pin that is supposed to be high at 0 input is high.
Good, now.. can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Show us how you connected the pot and show us how you have connected your sensor and power supply.
Tom...