Hi Everyone
After allot of effort I finally got my PSU up and running using the RC filter and PWM. But I need help with just one more thing. I attached my schematic of the MCU board that controls the PSU. I've removed the Max232 and all its components for now because it was not working. After allot of efferot I cannot get my ADC working. If there is anyone familiar with AVR's that could have a look at my schematic, board and code just to check where my problem could be.
The ADC keeps returning 1023 no matter what changes I make to the code or the hardware. PS swapped atmega8's as well
#include <avr/io.h>
#define PORT_ON(port,pin) port |= (1<<pin)
#define PORT_OFF(port,pin) port &= ~(1<<pin)
int main(void)
{
unsigned int adc_value; // Variable to hold ADC result
DDRB = 0b00000111;
PORTB = 0b11111000;
ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS0);
// Set ADCSRA Register with division factor 32
ADMUX=0x01; //Binary equivalent of 0101
while (1) //Forever since it is in single conversion mode
{
ADCSRA |= (1<<ADSC); // Start conversion
while (ADCSRA & (1<<ADSC));
// wait until conversion completes; ADSC=0 means Complete
adc_value = ADCW; //Store ADC result
if (adc_value < 512)
{
PORT_OFF (PORTB,2); // Set 7th bit
}
else
{
PORT_ON (PORTB,2); // Clear 7th bit
}
}
}