Vai al contenuto
PLC Forum


Conversioni A/D multiple e mikrobasic


aduri

Messaggi consigliati

Ho provato, per la prima volta, a vedere come funziona il convertitore A/D del pic16f877a ed ha funzionato alla prima ma ho provato ad apportare delle modifiche al codice MKB per avere la possibilita' di conversioni multiple ma non ha funzionato o per meglio dire funziona solo un canale e l'altro segue molto disturbato i valori del primo.

Il mio dubbio e' anche capire MKB cosa fa con i registri intco1 e intcon0 quando usa la macro ADC_read(2).

Qualcuno ha esperienze a proposito?

Allego il listato:

program adc2_lcd

'(*

' * Project name:

' adconlcd

' * Copyright:

' © mikroElektronika, 2005 - 2006

' * Revision History:

' 20050312:

' - initial release.

' * Description:

' This code demonstrates how to use library function ADC_read, and library

' procedures and functions for LCD display (4 bit interface)

' * Test configuration:

' MCU: PIC16F877A

' Dev.Board:

' Oscillator: HS, 4.000 MHz

' Ext. Modules: None

' SW: mikroBasic v5.0 or higher

' * NOTES:

' - If you are using EasyPIC4, use provided jumper on top right to connect potentiometer to RA2

' *)

dim ch1 as byte

ch2 as byte

t1 as word

t2 as word

Text1 as char[17]

Text2 as char[17]

tlong1 as longint

tlong2 as longint

main:

PORTB =0 ' clear portb

TRISB =0 ' designate portb as output (LCD is connected to portb)

intcon =0 ' disable all interrupts

Lcd_Init(PORTB) ' initialize (4-bit interface connection)

Lcd_Cmd( LCD_CURSOR_OFF) ' send command to LCD (cursor off)

Lcd_Cmd(LCD_CLEAR) ' send command to LCD (clear LCD)

Text1 ="A/D Aduri" ' assign text to string a

Lcd_Out(1,1, Text1) ' print string a on LCD, 1st row, 1st column

Text2 ="Prova" ' assign text to string a

Lcd_Out(2,1, Text2) ' print string a on LCD, 2nd row, 1st column

OPTION_REG = $80

ADCON1 = $82 ' configure VDD as Vref, and analog channels

TRISA = $FF ' designate porta as input

Delay_ms(2000)

Text1 = "voltage1:" ' assign text to string a

Lcd_Out(1,1,Text1) ' print string a on LCD, 2nd row, 1st column

Lcd_Chr(1,14,"V")

Text2 = "voltage2:" ' assign text to string a

Lcd_Out(2,1,Text2) ' print string a on LCD, 2nd row, 1st column

Lcd_Chr(2,14,"V")

while true

t1 = ADC_read(1) ' get ADC value from 1st channel

tlong1 = t1*5000

t1 = tlong1 >> 10

ch1 = t1 div 1000 ' prepare value for diplay

Lcd_Chr(1,11,48+ch1) ' write ASCII at first row, 9th column

Lcd_Chr(1,12,".")

ch1 = (t1 div 100) mod 10

Lcd_Chr(1,13,48+ch1)

ch1 = (t1 div 10) mod 10

Lcd_Chr(1,14,48+ch1)

ch1 = t1 mod 10

Lcd_Chr(1,15,48+ch1)

delay_ms(1)

t2 = ADC_read(2) ' get ADC value from 2nd channel

tlong2 = t2*5000

t2 = tlong2 >> 10

ch2 = t2 div 1000 ' prepare value for diplay

Lcd_Chr(2,11,48+ch2) ' write ASCII at 2nd row, 9th column

Lcd_Chr(2,12,".")

ch2 = (t2 div 100) mod 10

Lcd_Chr(2,13,48+ch2)

ch2 = (t2 div 10) mod 10

Lcd_Chr(2,14,48+ch2)

ch2 = t2 mod 10

Lcd_Chr(2,15,48+ch2)

delay_ms(1)

wend

end.

Cordiali saluti

Modificato: da aduri
Link al commento
Condividi su altri siti

  • 2 weeks later...

Sono riuscito a risolvere e funziona.

Non avevo letto bene il datasheet che limitava il valore dell'impedenza d'ingresso, ho sostituito i trimmer con valori piu' bassi ed ha funzionato perfettamente.

Spero che questo post possa servire ad altri per non commettere il mio stesso errore.

Link al commento
Condividi su altri siti

Mi spiace deluderti sad.gif ma e' un esempio di mikrobasic modificato per le mie esigenze. A/D su piu' canali l'originale era su un solo canale.

Ciao

Link al commento
Condividi su altri siti

Crea un account o accedi per commentare

Devi essere un utente per poter lasciare un commento

Crea un account

Registrati per un nuovo account nella nostra comunità. è facile!

Registra un nuovo account

Accedi

Hai già un account? Accedi qui.

Accedi ora
×
×
  • Crea nuovo/a...