336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

ADC0, ADC1을 이용하여 LED0 LED1을 ON,OFF

(tifoda wrote the code below▼)

ADC0,ADC1_Two LED ON,OFF Each.txt



  1. I hard for mecant check your functions. If you not sure - do simple test program to test them. Just while(1) and move your servo, print on lcd etc. Errors( warnings) i see is 1 - setting whole port when you need 1 pin only. Like PORTC = 0x20. You can forget something and set/reset pins you dont need to. Use PORTC |= 0x20 and PORTC &= ~(1<<0x20). 2 - this will not work 100% :) for(i=0; i<10; i++) { PORTE = 0b00000001; //Forward Rotation _delay_ms(2000); //2 sec + 10 times = 20sec }

  2. 어렵다. to chekc 네 function을
  3. If 네가 확실치않으면 - do 간단히 테스트해라. 
  4. 3 - COUNTA = ADC/20; //since the resolution (2.56/2^10 = 0.0025) is 2.5mV there will be an increment of 4 for every 10mV input, that means for every degree raise there will be increment of 4 in digital value. So to get the temperature we have to divide ADC output by four. But you have AVCC undefined as reference. So you have your input voltage as reference, but not internal 2.56
  5. 4 - PORTA = 0b00001111; //Fan OFF, Heater ON } else { PORTA = 0b11110000; //Fan ON, Heater OFF } Do you power FAN with 4 pins? Bad idea. Use 1 pin and external transistor or relay
  6. I advise you to test all functions separetly( if you not sure they are working good) and then combine.


ADC0    ADC1 (각각 온도, 가스)

Low    Low        :    Heater ON

Low    High        :    Heater ON + Servo 90º Fan ON

High    Low        :    Fan ON

High    High        :    Fan ON + Servo 90º


기존 회로상에서...

Low    Low    :    Servo 0    PB00000000        +    PA00001111(Heater ON)

Low    High    :    Servo 90    PB11111111    +    PA00001111(Heater ON)

High    Low    :    Servo 0       PB00000000  + PA11110000 (Fan ON)

High    High    :    Servo 90    PB11111111    +    PA11110000 (Fan ON)

===========================================================




#include <avr/io.h>

#include <util/delay.h>

#define F_CPU 16000000UL


//========================

// Turn OFF M103C fuse !!!

//========================



// Output pins setup, can be any pins of any port.

#define OUTPUT_PORT   PORTC

#define OUTPUT_DDR    DDRC

#define OUTPUT_PIN0   0

#define OUTPUT_PIN1   1

#define OUTPUT_PIN5   5


#define THRESHOLD0     127 // output is HIGH when adc value is greater than threshold. Max value is 255.

#define THRESHOLD1     127 // actually atmega has 10bit ADC, but least significant bits are always thrash. So we use only most significant 8 bits.



// ADC voltage reference ( uncomment ONE only)

//#define ADC_VREF_TYPE ((0<<REFS1) | (1<<REFS0) | (1<<ADLAR)) // AREF 

#define ADC_VREF_TYPE ((0<<REFS1) | (1<<REFS0) | (1<<ADLAR)) // AVCC

//#define ADC_VREF_TYPE ((1<<REFS1) | (1<<REFS0) | (1<<ADLAR)) // internal 2.56V


uint8_t read_adc(uint8_t);

void some_delay(uint16_t);



int main(void)

{

OUTPUT_DDR |= (1<<OUTPUT_PIN0) | (1<<OUTPUT_PIN1); // setup outputs


DDRC = 0xFF; //For Servo

DDRA = 0xFF;

DDRB = 0xFF;



ACSR=0x80; // turn off analog comparator

// ADC initialization

ADMUX=ADC_VREF_TYPE;

ADCSRA=(1<<ADEN) | (0<<ADSC) | (0<<ADFR) | (0<<ADIF) | (0<<ADIE) | (1<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);

SFIOR=(0<<ACME);

    while (1) 

    {

if(read_adc(1) > THRESHOLD0) //  read adc pin0 and

{

//OUTPUT_PORT |= (1<<OUTPUT_PIN0); // either turn ON led 0


for(int i=0; i<100; i++)

{

PORTC = 0x20; //0010 0000

// PORTC = 0x40;

_delay_us(600); //Degree 0

PORTC = 0x00;

_delay_ms(23);

}

PORTB = 0b11111111; //Fan is ON



//http://www.engineersgarage.com/sites/default/files/imagecache/Original/wysiwyg_imageupload/28714/Servo%20Motor%20Timing%20Diagram.jpg

//Servo Angle Information


}

else

{

//OUTPUT_PORT &= ~(1<<OUTPUT_PIN0); // or turn it OFF

for(int i=0; i<100; i++)

{

PORTC = 0x20;

//PORTC = 0x40;

//_delay_us(2400); //Degree 180

_delay_us(1500);

PORTC = 0x00;

_delay_ms(23);

}

PORTB = 0b00000000; //Fan is OFF


}

//some_delay(65000);



if(read_adc(0) > THRESHOLD1) // same with pin1

{

//OUTPUT_PORT |= (1<<OUTPUT_PIN1);

PORTA = 0b11110000; //Fan is ON

}

else

{

//OUTPUT_PORT &= ~(1<<OUTPUT_PIN1);

PORTA = 0b00001111; //Heater is ON

}

//some_delay(65000);

}

}


// Read the 8 most significant bits

// of the AD conversion result

uint8_t read_adc(uint8_t adc_input)

{

// Set multiplexer

ADMUX = adc_input | ADC_VREF_TYPE;

// Delay needed for the stabilization of the ADC input voltage

some_delay(100);

// Start the AD conversion

ADCSRA |= (1<<ADSC);

// Wait for the AD conversion to complete

while ((ADCSRA & (1<<ADIF)) == 0);

// Clear flag

ADCSRA |= (1<<ADIF);

return ADCH;

}


// Simple delay function

void some_delay(uint16_t delay)

{

uint16_t i;

for(i=0; i<delay; i++);

}


'졸업작품 > Multi ADC (AVR)' 카테고리의 다른 글

회로도 ()  (3) 2016.11.15
Posted by ElectricShock
:
BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
Programming(=프로그래밍) (3)
MiDi (2)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백