more adc help

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

OK, so here's my first attempt at reading the ADC from an attiny44 running on a 20MHz clock. I have a receiving ultrasonic transducer hooked up to the pin, but am not utilizing the transmitter at this time. Regardless, I think that I should be seeing a little noise on on pin 0 of the adc, but I am just getting solid 0's. Is my configuration correct?

Thanks!


#include 
#include 
#include 
#include 
#include 

#define txPin PA1 // transmit pin
#define rxPin PA2 // receive pin

#define outputSpeakerPinOne PA7
#define outputSpeakerPinTwo PB2

#define bitDelayTime 8.7 // bit delay, 1/115200 in usec at 20 MHZ
#define bitDelay() _delay_us(bitDelayTime) // RS232 bit delay
#define halfBitDelay() _delay_us(bitDelayTime/2) // RS232 half bit delay
#define outputA(pin) (DDRA |= byte(pin)) // set PORTA pin for output
#define outputB(pin) (DDRB |= byte(pin)) // set PORTB pin for output
#define setA(pin) (PORTA |= byte(pin)) // set pin in PORTA
#define clearA(pin) (PORTA &= ~(byte(pin))) // clear pin in PORTA
#define setB(pin) (PORTB |= byte(pin)) // set pin in PORTB
#define clearB(pin) (PORTB &= ~(byte(pin))) // clear pin in PORTB
#define pinTestA(bit) (PINA & (1 << bit)) // test for pin in PORTA
#define bitTest(byte,bit) (byte & (1 << bit)) // test for bit set
#define byte(bit) (1 << bit) // byte with bit set

volatile char rxbyte;

ISR(ADC_vect)  //ADC interrupt service routine
{
	rxbyte = ADCH;
}

void putChar(char txchar) {
	
	txchar = txchar ^ 0xFF;
	//
	// print the character in txchar
	//
	// start bit
	//
	clearA(txPin);
	bitDelay();
	//
	// unrolled loop to write data bits
	//
	if bitTest(txchar,0)
		clearA(txPin);
	else
		setA(txPin);
	bitDelay();
	if bitTest(txchar,1)
		clearA(txPin);
	else
		setA(txPin);
	bitDelay();
	if bitTest(txchar,2)
		clearA(txPin);
	else
		setA(txPin);
	bitDelay();
	if bitTest(txchar,3)
		clearA(txPin);
	else
		setA(txPin);
	bitDelay();
	if bitTest(txchar,4)
		clearA(txPin);
	else
		setA(txPin);
	bitDelay();
	if bitTest(txchar,5)
		clearA(txPin);
	else
		setA(txPin);
	bitDelay();
	if bitTest(txchar,6)
		clearA(txPin);
	else
		setA(txPin);
	bitDelay();
	if bitTest(txchar,7)
		clearA(txPin);
	else
		setA(txPin);
	bitDelay();
	//
	// stop bit 
	//
	setA(txPin);
	bitDelay();
}

int main(void)
{
	
	//
	// set clock divider to /1
	//
	CLKPR = (1 << CLKPCE);
	CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
	
	//Initialize ADC
	
	ADMUX = _BV(REFS1); //Set internal 1.1 voltage as reference; default pin to read is 0
	
	ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADIE) | _BV(ADPS2) | _BV(ADPS0); // Enable ADC.  Start conversions.  Enable conversion interrupt (remember to enable global interrupts).  Prescaler set to /32 (running at 625 kHz).
	
	ADCSRB = _BV(ADLAR); //Left shift the results so that i can just read off the 8-bit value because I am running it fast
	
	//
	// initialize output pins
	//
	
	outputA(txPin);
	setA(txPin);
	
	//
	// main loop
	//

        sei();  //enable interrupts
	while (1)
	{
		putChar(rxbyte);
		
		_delay_ms(100);
	}
}

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

Why don't you try to put an actual voltage on the pin and see what happens.

Regards,
Steve A.

The Board helps those that help themselves.

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

Ok, I tried putting 0.6 volts onto the pin, and still nothing......