Forum: Mikrocontroller und Digitale Elektronik ADC Wandlung PIC24FJ128


von Chris (Gast)


Lesenswert?

Hallo,

ich bin neu im Felder der PIC Controller, habe vorher nur mit AVRs 
gearbeitet.

Ich wollte einfach eine ADC Wandlung des Wertes an AN5 machen (bzw. 
später noch mehr Kanäle)... aber ich bekomme als Ergebnis immer 0! 
Obwohl 1,5 V anliegen.

Anschlüsse IC: VREF+ 3,0 V Referenzspannung
               VREF- NC
               AN5 1,5V zu messende Spannung (mit MM geprüft ob Spannung 
vorhanden)

Meine adc.c datei
1
#include <p24FJ128GA006.h>
2
#include "adc.h"
3
4
5
void ADC_Init(void)
6
{
7
8
  _ADON = 1; // AD Wanlder einschalten
9
  _VCFG = 0b001;  // Nutze +VRef als Referenz
10
  _ADRC = 0;  //Nutze SystemClock
11
  // Set analoge Eingänge als Input
12
  _TRISB2 = 0; 
13
  _TRISB3 = 0;
14
  _TRISB4 = 0;
15
  _TRISB5 = 0;
16
  _TRISB8 = 0;
17
  _TRISB9 = 0;
18
  _TRISB10 = 0;
19
  _TRISB11 = 0;
20
  _TRISB12 = 0;
21
  _TRISB13 = 0;
22
  _TRISB14 = 0;
23
  _TRISB15 = 0;
24
  // Setzte Analoge Eingänge auf Analog
25
  _PCFG2 = 0; 
26
  _PCFG3 = 0;
27
  _PCFG4 = 0;
28
  _PCFG5 = 0;
29
  _PCFG8 = 0;
30
  _PCFG9 = 0;
31
  _PCFG10 = 0;
32
  _PCFG11 = 0;
33
  _PCFG12 = 0;
34
  _PCFG13 = 0;
35
  _PCFG14 = 0;
36
  _PCFG15 = 0;
37
_SSRC = 0b000; // Manual Conversation
38
_ASAM = 0; // Auto Sampling off
39
_CSCNA = 0; // Select Channel manualy
40
_CH0NA = 0; // VSS is Negative Input
41
_SAMP = 1; // S/H Mode
42
_ALTS = 0; // Use MUX A
43
_SAMC = 0b00010; // Zeit (Anzahl Clock cycles) zwischen Sample und Conversion
44
_ADCS = 0b00000001; // 2xTCY
45
_CH0SA = 0b00101; // Channel 5 ADC Wandlung
46
47
48
}
49
50
51
unsigned int ADC_Read(int channel)
52
{
53
54
  // Starte Sampling
55
  _SAMP = 1; // Starte Sampling
56
  _delay_us(100); // Warte Sample Time
57
  _SAMP = 0; // Beende Sampling und Starte Convertion
58
59
  while (!_DONE); // Warte hier bis Convertion Done
60
61
  return ADC1BUF0;
62
}

Aufruf entsprechend in der main()

Was mache ich falsch?!

Gruß
Chris

von Arc N. (arc)


Lesenswert?

"The AD1PCFGL and TRIS registers control the operation of the A/D port 
pins. Setting a port pin as an analog input also requires that the 
corresponding TRIS bit be set. If the TRIS bit is cleared (output), the 
digital output level (VOH or VOL) will be converted."
(Datenblatt PIC24FJ256GA110)

von ich (Gast)


Lesenswert?

Chris schrieb:
> // Set analoge Eingänge als Input
>   _TRISB2 = 0;

Für einen Input muss das TRIS-Bit auf 1. Ist glaube genau anders wie 
beim AVR. 1 wie I -> Input, 0 wie O -> Output

von Chris (Gast)


Lesenswert?

Ohhhhh maaan.... da fummel ich schon 2 Tage an dem Teil rum und dann ist 
es sooo einfach ^^.

Ja ist genau anders rum wie beim AVR - wusst ich eigentlich auch, aber 
so wie es hier ausschaut hab ich das noch nicht wirklich verinnerlicht 
:-D

Funzt alles - DANKE!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.