Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

2 analog inputs code .. anyone please?

Status
Not open for further replies.

scope4ever

New Member
hi guys ,

i am using a pic18F4520 - Micro chip.

i am trying to make a code that detects 2 inputs (Temperature sensor and an Occupancy sensor).

does anyone have any idea how to do that.

As am a beginner in this and i need to get it working before next wednesday.

THANKS in ADVANCE.
 
Simple description:

1. Set ADC channel to Temperature sensor input.
2. Wait Tad cycles (see PIC datasheet).
3. Start A/D conversion.
4. When A/D conversion finishes, get value and store.
5. Set ADC channel to Occupancy sensor input.
6. Wait Tad cycles (see PIC datasheet).
7. Start A/D conversion.
8. When A/D conversion finishes, get value and store.
9. Repeat from step 1.

Somewhere inside this loop you'll want to use the values you got to achieve whatever function your project is meant to do.
 
hi what language are you using for programming? a few things to help you get started are. you have to make the ADC pins anologue as opposed to digital (see datasheet) you will have to make the anologue pins input (TRIS register). if you using C18 microchip supplies ADC libs wich may help you out
 
hi what language are you using for programming? a few things to help you get started are. you have to make the ADC pins anologue as opposed to digital (see datasheet) you will have to make the anologue pins input (TRIS register). if you using C18 microchip supplies ADC libs wich may help you out

I want to use the c language , but do you think it will be the easiest to be used in my situation? coz am not really into coding =S
 
Simple description:

1. Set ADC channel to Temperature sensor input.
2. Wait Tad cycles (see PIC datasheet).
3. Start A/D conversion.
4. When A/D conversion finishes, get value and store.
5. Set ADC channel to Occupancy sensor input.
6. Wait Tad cycles (see PIC datasheet).
7. Start A/D conversion.
8. When A/D conversion finishes, get value and store.
9. Repeat from step 1.

Somewhere inside this loop you'll want to use the values you got to achieve whatever function your project is meant to do.

Thanks for the steps, but which language do i use that you think is more easier and efficient and if you can help me in it i would be thankful.
 
Do you no how to use VB? If so I would try Swordfish Basic and reading temp would be easy

Code:
Function ADC_value() As Word
    
        result = ((ADC.Read(0)*4300)/1023)/10     
End Function


Dim ADVal As Word
Dim temp As Word

// main program loop - this just simply reads a byte from a
// terminal window (for example, SerialCommunicator) and then
// echo it back...
TRISA = %00000011        // configure AN0 as an input 
ADCON1 = %00001101       // set analogue input on PORTA.0 
While true
     temp = ADC_value
    
      DelayMS(100)
      Writebyte(temp)
        DelayMS(1000)
Wend
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top