ADC PIC18F46K80 keine Funktion

Support-Forum für Deutschsprachige, die in ihrer Muttersprache schreiben möchten.

Moderator: Benj

Post Reply
PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hallo an Alle!

Brauche dringend Hilfe.
Ich bekomme keine Eingangswerte egal von welchem Port.
Ich bekomme keine Eingangswerte egal wie ich Werte einlesen will.
Mit und ohne Spannung kommen immer im Wechsel 0.31xxxxx und 0.93xxxx. als Flot oder String ausgelesen
Mit und ohne Spannung kommen immer im Wechsel 63 oder 192 als Byte und 255 oder 768 als Int.
Der Chip läuft mit 64Mhz 2x Serielle Schnitstelle 1x I2C Buß 4x Analogeingang und 1x EEprom vom Chip selbst.
Eine RS232 ist erst im Betrieb für einen Touchscreen. I2C läuft noch nicht. EEprom ist in Betrieb.

Kann es sein das der Chip noch nicht richtig implementiert ist?

mit freundlichem Gruß
PIC-Speed32

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by Benj »

Hallo,

I have replied to your post here.
http://www.matrixmultimedia.com/mmforum ... 729#p40729

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Die ADC Abfrage funktioniert.
Neues Problem:
Der ADC Wert überschreibt ein Stringvariable S minwert(29) die nichts mit dem ADC Wert S ADC0(20) zu tun hat. Ich habe deshalb eine neue Variable angelegt S Analog1(20), die im Makro ADC das erste mal verwendet wird. Das zweite mal wird sie in der seriellen Ausgabe benutzt.
Jetzt wird eine andere Variable S maxwert(20) die damit auch nichts zu tun hat überschrieben.

Danke schon mal Uwe

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by Benj »

Hallo Uwe,

Leider kannst du bitte das Problem zu beschreiben vielleicht wieder bietet ein Beispiel, um mir helfen zu verstehen, und ich werde in sie für Sie suchen.


Hello Uwe,

Sorry please can you describe the problem again maybe providing an example to help me understand and I will look into it for you.

Jojo1981
Posts: 28
Joined: Wed Feb 29, 2012 9:23 pm
Been thanked: 3 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by Jojo1981 »

Hallo Uwe,

den Fehler macht aber nur der PIC selber, die Simulation in FlowCode ist fehlerfrei, oder?

Ich hatte bei einem PIC18F25K22 auch das gleiche Problem mit überschreibenden Registern.

Prüfe doch mal ob das XINST Bit an ist oder nicht.
REGISTER 28-1: CONFIG1L: CONFIGURATION REGISTER 1 LOW (BYTE ADDRESS 300000h)
U-0 R/P-1 U-0 R/P-1 R/P-1 R/P-1 U-0 R/P-1
— XINST — SOSCSEL1 SOSCSEL0 INTOSCSEL — RETEN
bit 7 bit 0
Legend: P = Programmable bit
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 7 Unimplemented: Read as ‘0’
bit 6 XINST: Extended Instruction Set Enable bit
1 = Instruction set extension and Indexed Addressing mode are enabled
0 = Instruction set extension and Indexed Addressing mode are disabled (Legacy mode)
War bei mir der Fehler da FlowCode und BoostC die Erweiterung nicht können.

VG,

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hallo Jojo 1981,

schon mal Danke. Die Simulation in Flowcode nutze ich nicht. Hintergrund ist ein Touchdisplay mit Serieller Schnittstelle. 480 x 272 Pixel von der Firma 4D Systems.
Ich programmiere ein wenig und schicke es zum PIC. Da teste ich es bevor ich weiter programmiere. Das ist zwar Zeitaufwendig aber ich sehe sofort meine Fehler, oder die von V5.
Ich programmiere im Moment ersteinmal die Benutzeroberfläche von meinem Projekt.
Das Ganze wird ein Messgerät für Gaskonzentrationen nach der Wärmeleitfähigkeitsprinziep von Gasen.
Es kann dann z.B. 45% O2 in N2 messen...

Ich arbeite noch nicht lange mit V5. Das ist erst mein zweites Projekt.
So, jetzt zu dem Vorschlag. Wo sehe ich diese Einstellungen? Steht das im C Code?
Wenn ja, müßte ich doch in einem C Ikon dieses Register umprogrammieren, oder?

Mit freundlichem Gruß
Uwe

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hallo Benj,

Ich schicke über RS232 zum Display Daten. Eine Variable minwert, maxwert, und ADC0. Alle 3 Variable sind Strings.
In minwert und in maxwert stehen zweistellige Zahlenwerte, die beim Start der Software aus dem EEprom gelesen werden.
In der Software kann ich diesen Variablen über den Touchscreen andere Werte geben, die dann im EEProm gesichert werden.
Mehr mache ich im Moment noch nicht damit. Die Variable ADC0 ist im Moment nur dazu da, um den AD Eingang zu testen.
Also AD Eingang lesen und als String über RS232 an den Screen schicken.
Das ganze in einer Endlosschleife.
Nachdem ich die Beiden Dateien von Dir ausgetauscht habe, passierte folgendes.
Die Anzeige mit der Variablen minwert zeigt im gleichen Takt wie die Anzeige des ADCO, ständig irgendwelche zufälligen Zeichen.
Nachdem ich eine neue Variable für den AD Wert angelegt habe und ADC0 gegen diese getauscht habe, ist der Fehler auf die Anzeige von maxwert gesprungen.
Jetzt macht die Anzeige von maxwert das gleiche wie vorher minwert. Minwert steht dafür stabil mit den richtigen Werten aus dem EEProm.

Mit freundlichem Gruß
Uwe




Hi Benj,

I send via RS232 to display data.A variable Minvalue, a variable maxvalue, and a variable ADC0. All 3 variables are strings.
In minvalue and maxvalue are two-digit numbers that can be read when the software starts from the EEprom.
In the software, I can these variables using the touchscreen be other values ​​that are then saved in EEPROM.
That's all I'm doing at the moment . The variable ADC0 is currently only there to test the AD input.
So read AD input and send a string via RS232 to the screen.
The whole in a continuous loop.
I change the two files from you, the following happened.
The display shows the variables minvalue the same rhythm as the display of ADCO, constantly any random characters.
After I created a new variable for the AD value and have exchanged ADC0 against this, the error on the display of maxvalue jumped.
Now the display does the same as before minvalue. Now minvalue is stable with the correct values ​​from the EEPROM.

Sincerely
Uwe

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hi Jojo 1981, Hi Benj

Meinst Du: Did you mean:

28.1 Configuration Bits
The Configuration bits can be programmed (read as
‘0’) or left unprogrammed (read as ‘1’) to select various
device configurations. These bits are mapped starting
at program memory location, 300000h.
The user will note that address, 300000h, is beyond the
user program memory space. In fact, it belongs to the
configuration memory space (300000h-3FFFFFh),
which can only be accessed using table reads and
table writes.
Software programming the Configuration registers is
done in a manner similar to programming the Flash
memory. The WR bit in the EECON1 register starts a
self-timed write to the Configuration register. In normal
operation mode, a TBLWTinstruction with the TBLPTR
pointing to the Configuration register sets up the address
and the data for the Configuration register write. Setting
the WR bit starts a long write to the Configuration
register. The Configuration registers are written a byte at
a time. To write or erase a configuration cell, a TBLWT
instruction can write a ‘1’ or a ‘0’ into the cell. For
additional details on Flash programming, refer to
Section 7.5 “Writing to Flash Program Memory”.
Table28-1.jpg
Table28-1.jpg (219.46 KiB) Viewed 20699 times
Muß ich das Bit XINST einschalten?


Mit freundlichem Gruß
Uwe

Ich kann erst am Wochenende weiter machen.

Danke nochmals.

Do I turn on the bit XINST?


Sincerely
Uwe

I can only go on the weekend.

Thank you again.

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hier mein Code.

Here is my code.
HTK4fcf.fcf
(201.52 KiB) Downloaded 511 times

Jojo1981
Posts: 28
Joined: Wed Feb 29, 2012 9:23 pm
Been thanked: 3 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by Jojo1981 »

Hallo Uwe,

du must Bit6 (XINST) im Config1L auf 0 setzten um die erweiterte Instruktionen von den neuen 18F- Pics auszuschalten. Flowcode und BoostC kann es nicht und dadurch kommen falsche Sprungbefehle ab der RAM- Adresse 0x05F.

Schau dir doch mal im c- File an wo deine sich ändernden Variablen abgelegt sind, ich vermute stark genau an dieser Stelle.

Es wird auch sicherlich kein sinnvoller Inhalt in der geänderten Variable abgelegt sein.

VG,
Jojo

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hallo Jojo1981,

habe vorher nur in Basic programmiert.
Finde mich schwer zurecht im C-Code.

hier ein Ausschnitt des C-Code


//Konfigurations-Daten
#ifdef _BOOSTC
#pragma DATA 0x300000, 0x59
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300001, 0x12
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);
#endif
#ifdef _BOOSTC
#pragma DATA 0x300002, 0x67
#endif
#ifdef _HI_TECH_C
%C__CONFIG(%A, %V);

Sieht für mich so aus als würden hier Speicherbereiche definiert.

Wie sage ich V5 nun, das XINST zu 0 wierd.

bei:
/*
Füge C-Code nach diesem Kommentar ein
*/
xinst=0;

meckert V5 " HTKx.c(2022:2): error: unknown identifier 'xinst' "
wenn ich Config1l einsetze, muß ich wissen welchen Wert die anderen bits haben.
Steht das auch im C-Code?


mit freundlichem Gruß Uwe

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hi, habs selbst gefunden.

Das Xinst bit wird unter Projekt-Optionen Konfiguriere Chip Extendet Instruction Set Disablet.
Unten rechts im Fenster, geht dann Config1L von 0x59 auf 0x19.
Config Chip.jpg
Config Chip.jpg (108.15 KiB) Viewed 20689 times
Werde es testen.

Ich habe bei der Simulation festgestellt, das im Panel die RS232 Schnitstelle verschwindet.
Schalte ich die Simulation aus, kommt das Fenster wieder und dann sehe ich auch den Inhalt des Senden Fensters?

Mit freundlichem Gruß
Uwe

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hallo Jojo1981,

das Überschreiben ist weg, soweit ich es getestet habe.


Danke und Gruß Uwe

Jojo1981
Posts: 28
Joined: Wed Feb 29, 2012 9:23 pm
Been thanked: 3 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by Jojo1981 »

Na schau her, hatte es schon Sinn dass ich damals auch über die Stolperfalle gestolpert bin.

Danke fürs Feedback und viel Spaß noch damit.

VG

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hi Benj,

is this ok?

// ADC Type 32 Supported Devices ***********************************************************
// 18F2xK80, 18F4xK80, 18F6xK80
// *****************************************************************************************/

#ifdef MX_ADC_TYPE_32
void FC_CAL_Enable_ADC (MX_UINT8 Channel, MX_UINT8 Conv_Speed, MX_UINT8 Vref, MX_UINT8 T_Charge)
{
adcon1 = 0;
"""""""""""""

adcon0 = adcon0 | 0x02; //begin conversion and wait until it has finished
while (adcon0 & 0x02);
if (Sample_Mode)
{
iRetVal = (adresh << 2); //10-bit ADC
iRetVal = iRetVal | (adresl >> 6);
}
else
iRetVal = adresh; //8-bit ADC

return (iRetVal);


[Defines]
Define1=#define P18LF46K80
Define2=#define FC_CAL_PIC
Define3=#define MX_ADC
Define4=#define MX_ADC_TYPE_32
Define5=#define MX_ADC_BITS_12
Define6=#define MX_EE

I think the 12bit missing here

Should it look like this

adcon0 = adcon0 | 0x02; //begin conversion and wait until it has finished
while (adcon0 & 0x02);
if (Sample_Mode)
{
iRetVal = (adresh << 4); //12-bit ADC
iRetVal = iRetVal | (adresl >> 4);
}
else
iRetVal = adresh; //8-bit ADC

return (iRetVal);


Sincerely
Uwe

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hallo, habe noch ein Problem.

1. Der PIC18F46K80 hat 12Bit Analogeingänge. In der PIC_Cal_ADC_c ist für diese PIC Familie nur 10 und 8 vorgesehen.(Soweit ich das verstehe)

2. Der PIC besitzt Differenzeingänge als Analogeingang.
Das Heist er kann direkt die Spannungswerte zwischen 2 Analogeingängen messen.
Dabei kommen auch negative Spannungswerte raus.
Das kann durch die Konfiguration bestimmt werden.
Z.B. kann ich sagen AN0 ist + und An1 ist -. Dann kann ich eine 1,5Volt Batterie dierkt an beide Anschlüsse legen und erhalte einmal 1,5Volt + oder wenn die Batterie gedreht wird 1,5Volt -.
In meinem Projekt brauche ich das nicht.
Ich weiß jetzt nicht, ob V5 das schon so konfiguriert.

Mein Problem:
Ich messe ADC2. ADC2 ist mit dem PIC Bein AN6 verbunden. ADC2 hat als Referenz VDD 500 x 10mV Fosc/64.
Der Anschluß ist jetzt mit 0Volt verbunden. Die Messung zeigt mir 4,99 an??????
Ist der Eingang offen, geht der Wert zurück und schwankt wie bei einem offenen Eingang üblich.

mit freundlichem Gruß
Uwe


Hi, I have a problem.

First The PIC18F46K80 has 12 bit analog inputs. In PIC_Cal_ADC_c for this PIC family only 10 and 8 is provided. (As far as I understand it)

Second The PIC has differential inputs as analog input.
That means it can directly measure the voltage between 2 analog inputs.
Here come out and negative voltage values​​.
Which may be determined by the configuration.
E.G. all I can say is AN0 + and An1 is -. Then I can put a 1.5 volt battery dierkt to both terminals and get a mere 1.5 volts + or when the battery is rotated 1.5 volts -.
In my project I do not need that.
I do not know whether the V5 already configured Sun

My problem:
I measure ADC2. ADC2 is connected to the PIC leg AN6. ADC2 has a reference VDD 500 x 10mV Fosc/64.
The connection is now connected to 0Volt. The measurement shows me at 4.99??
If the input is open, returns the value fluctuates and as is usual for an open entrance.

with kind regards
Uwe

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Noch eine Frage:
Vom PIC18f46K80 gibt es eine Version mit 40 PIN und 44 PIN Gehäuse.
Die FCD Datei ist für die 40PIN Version.
Ich benutze die 44 PIN Version.

Die Belegung der PINs ist komplett unterschiedlich.
Gibt es keine 2 unterschiedlichen FCD Dateien ?

Kann dadurch der Fehler kommen, das ich 4,99 messe,
wenn der Eingang auf 0Volt liegt?

Mit freundlichem Gruß
Uwe



One more question:
From PIC18f46K80 there is a version with 40 pin and 44 pin package.
The FCD file is for the 40pin version.
I use the 44 pin version.

The assignment of the PINs is completely different.
There are no two different FCD files?

May come in the error, which I measure 4.99,
when the input is at 0Volt?

Sincerely
Uwe

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hallo alle.
Ich habe in PICBasic Pro (Mikroelektronika)den Analogeingang abgefragt.
Diese Software macht es richtig.
Das heist, meine Hardware ist richtig aufgebaut.

Ich habe mal die Beschreibungsdatei des PIC angehängt.
Ich hoffe das hilft.

Mit freundlichem Gruß
Uwe



Hello all.
I queried in PICBasic Pro (Mikroelektronika) the analog input.
This software makes it right.
That means, if my hardware is set up properly.

I once attached the description file of the PIC.
I hope this helps.

Sincerely
Uwe
Attachments
P18LF46K80.zip
(26.81 KiB) Downloaded 357 times

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hi Benj,

ich teste heute mal nur den Analogeingang.
Die Datei schicke ich Ihnen.

Mit freundlichem Gruß
Uwe


Hi Benj,

I test today times the analog input only.
I'll send you the file.

Sincerely
Uwe

PIC-Speed32
Posts: 33
Joined: Tue May 08, 2012 3:48 pm
Location: Germany
Has thanked: 7 times
Contact:

Re: ADC PIC18F46K80 keine Funktion

Post by PIC-Speed32 »

Hallo alle,

ich glaube der Fehler liegt in der Konfiguration des PIC.
Der PIC hat 2 Referenzspannungen.
2,048V und 4,096V.
Ich glaube, der PIC ist auf 4,096V eingestellt.
Bei 0Volt am Eingang misst er 4,99V.
Bei 12mV am Eingang misst er 0,00V.
Bei 3,98V am Eingang misst er 4,02V
Bei 4,4V am Eingang misst er 4,04V
Bei 4,94V am Eingang misst er 3,85V
Zwischenwerte habe ich nicht mehr gemessen.
Ich brauche die Externe Referenz(+) an PIN AN3.
Referenz(-) an GND.
Die AD Eingänge als Einzeleingang.
Der fehler liegt warscheinlich hier.

bit 7-6 TRIGSEL<1:0>:Special Trigger Select bits
11= Selects the special trigger from the CCP2
10= Selects the special trigger from the Timer1
01= Selects the special trigger from the CTMU
00= Selects the special trigger from the ECCP1
bit 5-4 VCFG<1:0>: A/D VREF+ Configuration bits
11= Internal VREF+ (4.096V)
10= Internal VREF+ (2.048V)
01= External VREF+
00= AVDD
bit 3 VNCFG: A/D VREF- Configuration bit
1=External VREF
0=AVSS
bit 2-0 CHSN<2:0>:Analog Negative Channel Select bits
111= Channel 07 (AN6)
110= Channel 06 (AN5)
101= Channel 05 (AN4)
100= Channel 04 (AN3)
011= Channel 03 (AN2)
010= Channel 02 (AN1)
001= Channel 01 (AN0)
000= Channel 00 (AVSS)

Mit freundlichem Gruß
Uwe

----------------------------------------------------------------

Hi all,

I think the fault lies in the configuration of the PIC.
The PIC has two reference voltages.
2.048 V and 4.096 V.
I think the PIC is set to 4.096V.
0Volt at the entrance, it measures 4.99 V.
At 12mV at the input, it measures 0.00 V.
At 3.98 V at the input, it measures 4.02 V
At 4.4 V at the input, it measures 4.04 V
At 4.94 V at the input, it measures 3,85 V
Between values ​​I have not measured.
I need the External Reference (+) to pin AN3.
Reference (-) to GND.
The AD inputs for single input.
The error is probably here.

bit 7-6 TRIGSEL <1:0>: Special Trigger select bits
11 = Selects the special trigger from the CCP2
10 = Selects the special trigger from the Timer1
01 = Selects the special trigger from the CTMU
00 = Selects the special trigger from the ECCP1
bit 5-4 VCFG <1:0>: A / D VREF + Configuration bits
11 = Internal VREF + (4.096V)
10 = Internal VREF + (2.048V)
01 = External VREF +
00 = AVDD
VNCFG bit 3: A / D VREF Configuration bit
1 = External VREF
0 = AVSS
bit 2-0 CHSN <2:0>: Analog Channel Select bits Negative
111 = Channel 07 (AN6)
110 = Channel 06 (AN5)
101 = Channel 05 (AN4)
100 = Channel 04 (AN3)
011 = Channel 03 (AN2)
010 = Channel 02 (AN1)
001 = Channel 01 (AN0)
000 = Channel 00 (AVSS)

Sincerely
Uwe

Post Reply