Basic programming of Atmel AVR ATmega168 microcontroller
$30-100 USD
En curso
Publicado hace más de 13 años
$30-100 USD
Pagado a la entrega
I need to finish a version of this project with a couple of tweaks. [login to view URL] First one is to remove the excite outputs from the mcu, so I can excite the bridge straight from the 5v rail. If this is successful there are a few other mods that need to be made. First post so I thought I'd keep it simple to start. Cheers Alan UK
## Deliverables
Remove output PD3 & 4 +/- alternating excite voltages from program (bridge will be excited from 5v rail) Current code // weighscale.c // for NerdKits with ATmega168 #define F_CPU 14745600 #include #include #include #include #include #include "../libnerdkits/delay.h" #include "../libnerdkits/lcd.h" #include "../libnerdkits/uart.h" // PIN DEFINITIONS: // PC0 -- analog in // // PD4 - bridge excite // PD3 - bridge excite void adc_init() { // set analog to digital converter // for external reference (5v), single ended input ADC0 ADMUX = 0; // set analog to digital converter // to be enabled, with a clock prescale of 1/128 // so that the ADC clock runs at 115.2kHz. ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); // fire a conversion just to get the ADC warmed up ADCSRA |= (1<<ADSC); } uint16_t adc_read() { // set ADSC bit to get the *next* conversion started ADCSRA |= (1<<ADSC); // read from ADC, waiting for conversion to finish // wait for it to be cleared while(ADCSRA & (1<<ADSC)) { // do nothing... just hold your breath. } // bit is cleared, so we have a result. // read from the ADCL/ADCH registers, and combine the result // Note: ADCL must be read first (datasheet pp. 259) uint16_t result = ADCL; uint16_t temp = ADCH; result = result + (temp<<8); return result; } int main() { // set PD3, PD4 as outputs DDRD |= (1<<PD3) | (1<<PD4); // init ADC adc_init(); // init serial port uart_init(); FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); stdin = stdout = &uart_stream; int16_t reading; while(1) { // set polarity +- PORTD |= (1<<PD3); PORTD &= ~(1<<PD4); // wait 5 time constants (bw=12kHz, T=13.2us) delay_us(66); // take reading //reading = adc_read(); printf_P(PSTR("%d "), adc_read()); // set polarity -+ PORTD |= (1<<PD4); PORTD &= ~(1<<PD3); // wait 5 time constants (bw=12kHz, T=13.2us) delay_us(66); // take reading //reading = reading - adc_read(); printf_P(PSTR("%d\r\n"), adc_read()); // send over serial port //printf_P(PSTR("%d\r\n"), reading); } return 0; }
## Platform
MCU is ATmega168