Problems in setting & clearing pins of ATxMEGA32 A4u

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,

 

I am new to avr micro-controllers and thus had a few basic questions. Thank you in advance for all the suggestions.

I am writing the following code to set and clear following pins of ATxMEGA32 A4u: (PINs are connected to SPST switches in DG612 IC. )

 

#include <avr/io.h>

void main( void )

 

{

//setup pins as output.
    PORTE.DIRSET = PIN1_bm; //switch0
    PORTE.DIRSET = PIN0_bm; //switch1
    PORTE.DIRSET = PIN2_bm; //switch2
    PORTE.DIRSET = PIN3_bm; //switch3

 //set initial switch positions
    PORTE.OUTCLR = PIN1_bm; //switch0
    PORTE.OUTSET = PIN0_bm; //switch1
    PORTE.OUTCLR = PIN2_bm; //switch2
    PORTE.OUTCLR = PIN3_bm; //switch3

 

}

 

Thus I want a high at PIN0 (i.e 3v) and low (i.e. 0v) for rest of the mentioned PINs. However I get 3.3v at PIN0 and get 2-3v at other PINs. I am not sure why do I get these voltages. I made sure that ground, AVCC & VCC pins get the proper voltages.  I also checked my connections and no short appears in the pins. Please let me know what might be the problem.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has timer T0 been initialized for pwm output? 

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Jim,

 

I had not done it initially but now I have. Still it did not affect my output.

Thanks

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just out of interest:

    PORTE.DIRSET = PIN1_bm; //switch0
    PORTE.DIRSET = PIN0_bm; //switch1
    PORTE.DIRSET = PIN2_bm; //switch2
    PORTE.DIRSET = PIN3_bm; //switch3

why 4 writes to the same register? Why not simply:

    PORTE.DIRSET = PIN1_bm | PIN0_bm | PIN2_bm| PIN3_bm; //switches 0..3

Anyway in #1 you said:

pratikpade wrote:
Thus I want a high at PIN0 (i.e 3v) and low (i.e. 0v) for rest of the mentioned PINs. However I get 3.3v at PIN0 and get 2-3v at other PINs.

Exactly what pins are you testing? The actual pin numbers for PORTE are:

 

 

So with your code I'd expect pin 28 to be 3.3V and pins 29, 32 and 33 to be 0V.

 

(that's always assuming those 4 pins aren't already attached to some other circuitry).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

Thanks for suggesting a simpler way to set the directions. For the voltages I am measuring at pins 28, 29, 32, 33. I found out the problem, it was due to a faulty switch IC to which I had connected these PORTE pins.

Thanks a lot!