Author Topic: Random pins getting set high, what could be causing this?  (Read 1771 times)

0 Members and 1 Guest are viewing this topic.

Offline z.s.tar.gzTopic starter

  • Supreme Robot
  • *****
  • Posts: 540
  • Helpful? 5
  • Linux Guru
Random pins getting set high, what could be causing this?
« on: November 23, 2009, 06:17:46 AM »
My code should turn only one pin in group B high, and all the rest should just do nothing.
Instead, 2 other pins from B, 3 from C, and 2 from A come on. Every time.

Where should I start troubleshooting this?

I have an atmega644 and am using avra/avrdude.
Save yourself the typing. Just call me Zach.

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: Random pins getting set high, what could be causing this?
« Reply #1 on: November 23, 2009, 06:38:50 AM »
Have you programmed all the other pins to be low? Never assume an unprogrammed pin will be at a certain logic level on a microcontroller.

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: Random pins getting set high, what could be causing this?
« Reply #2 on: November 23, 2009, 05:37:22 PM »
Don't they have built-in pull-down resistors?

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: Random pins getting set high, what could be causing this?
« Reply #3 on: November 23, 2009, 06:00:52 PM »
They have pull up resistors which are selectable when pins are configured as inputs. However if pull ups are not enabled on inputs the pins are high impedance and floating, so all bets are off.

It is generally good practice with a micro to configure all the pins, even if you are not using them. You will find this advice in the datasheets for most micros. The ATmega sheets recommend configuring unused pins as inputs and enabling pull ups.

Offline z.s.tar.gzTopic starter

  • Supreme Robot
  • *****
  • Posts: 540
  • Helpful? 5
  • Linux Guru
Re: Random pins getting set high, what could be causing this?
« Reply #4 on: November 23, 2009, 06:42:07 PM »
I see what you're saying.
Lets see what happens if I set everything to zero first...

Nope. No change.
« Last Edit: November 23, 2009, 07:03:26 PM by z.s.tar.gz »
Save yourself the typing. Just call me Zach.

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: Random pins getting set high, what could be causing this?
« Reply #5 on: November 24, 2009, 02:37:55 AM »
When you say "set everything to zero first..." what exactly do you mean?

You need to:
1) Configure a pin to be an input or output by setting the corresponding bit in the DDRx register (where x is the port you are configuring, so DDRC for port C) to be 0 for an input or 1 for an output.
2) Configure the corresponding bit of the PORTx register to set:
  - The pin high or low if it is configured as an output.
  - Enable pull up resistors (set as 1) or leave the pin to float (set as 0).

So "setting everything to zero" will configure pins as floating inputs ???

If pins are floating then the behaviour you see isn't really anything to worry about unless it affects anything else in your circuit. If you are sure they are not floating then check for shorts between pins in your circuit. Finally suspect problems with the microcontroller (very unlikely).

Offline z.s.tar.gzTopic starter

  • Supreme Robot
  • *****
  • Posts: 540
  • Helpful? 5
  • Linux Guru
Re: Random pins getting set high, what could be causing this?
« Reply #6 on: November 24, 2009, 12:25:59 PM »
When I say write everything to zero, I mean I write 0x00 to all the pin's registers. (ddr, pin, and port, for a,b,c, and d)
This should make it all the pins floating input, but some still keep outputing 5V regardless.

I think it might actually be a problem with the MCU, because the problem persists even when I wipe the eeprom. (there is no program loaded at all)

Could it be a problem with the socket I have the IC in?
Save yourself the typing. Just call me Zach.

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: Random pins getting set high, what could be causing this?
« Reply #7 on: November 25, 2009, 03:32:11 AM »
Floating means that pins have no defined level and could have any voltage when you measure them, including 5V. Also this value could change depending on the internal configuration of the micro or external effects in your circuit. Measuring the voltage on floating pins is meaningless.

To test if pins are floating load the pins. A floating input can have any voltage, but it should not supply any current. Connect them to 0V via a 10kOhm resistor and test their voltage again. If they were floating they should now read 0V. If they do then their behaviour is likely normal and should be no need to worry about it (but if it bothers you pull them high using the internal pull ups or low with external resistors). If not there is another problem... 

Test is that there are no shorts on the board which could cause what you are seeing. Note which pins show this behaviour then remove the micro and test resistance between the pins in question and your output pin, repeat for +5V. If you see a low resistance then this is possibly the cause. Power up the circuit and do a voltage test on the pins without the micro in it's socket. If they are +5V the problem is somewhere on your board.

 

Offline z.s.tar.gzTopic starter

  • Supreme Robot
  • *****
  • Posts: 540
  • Helpful? 5
  • Linux Guru
Re: Random pins getting set high, what could be causing this?
« Reply #8 on: November 25, 2009, 06:36:23 AM »
The real issue isn't the floating ones really, it's the fact that the ones I want to be output aren't doing anything.

I'm going to set everything to pull up and see what that gives me.

Edit: I changed everything to output low (ground?) and at least it changed. Now instead of outputting 5V, it outputs 1.5V

I'm gonna check my code a little more, I think I have some bits mixed up.
« Last Edit: November 25, 2009, 09:24:00 AM by z.s.tar.gz »
Save yourself the typing. Just call me Zach.

Offline z.s.tar.gzTopic starter

  • Supreme Robot
  • *****
  • Posts: 540
  • Helpful? 5
  • Linux Guru
Re: Random pins getting set high, what could be causing this?
« Reply #9 on: November 25, 2009, 10:32:06 AM »
I completely redid the circuit on a breadboard, and now I'm getting other problems.
I wrote a program to set every pin to 5V out, but it doesn't work.

Code: [Select]
;build 10
.device atmega644
.nolist
.include "m644.inc"
.list


ldi r16, 0xFF ;set all pins to act as ground
sts ddrA, r16
sts ddrB, r16
sts ddrC, r16
sts ddrD, r16

sts portA, r16
sts portB, r16
sts portC, r16
sts portD, r16

ldi r16, 0x00
sts pinA, r16 ;set the pins too just in case
sts pinB, r16
sts pinC, r16
sts pinD, r16


ldi r16, 0xFF ;set all pin D to output
sts portD, r16

infloop:
rjmp infloop

Do I need to use 'out' to make it 5V, or should I be able to just set the bytes and let them be?
Save yourself the typing. Just call me Zach.

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: Random pins getting set high, what could be causing this?
« Reply #10 on: November 26, 2009, 04:16:47 AM »
Use out instead of sts. Using sts you are writing to the wrong registers and not configuring the ports. There should be no need to write to the pins, see the datasheet for more information and useful assembly examples for configuring the device. Also the ATMega instruction set for a description of the assembly instructions.

When writing in assembler you really need to use a simulator to test your code. It lets you see what your code is doing inside the micro and makes debugging far easier (and by far easier I mean actually possible). Simulate as you code, before you burn code to the micro, this will save you time and frustration ;).

Breadboard is useful for prototyping but you have to watch it. It usually gives me pesky random connection issues >:( Check the circuit carefully with a meter if you see anything odd going on.

 

Offline z.s.tar.gzTopic starter

  • Supreme Robot
  • *****
  • Posts: 540
  • Helpful? 5
  • Linux Guru
Re: Random pins getting set high, what could be causing this?
« Reply #11 on: November 26, 2009, 07:54:03 AM »
What is some good simulation software for linux then?
I've heard of simulavr, but I haven't tried it.
Save yourself the typing. Just call me Zach.

 


Get Your Ad Here

data_list