AnsweredHot!ADC dispic33 doesnt work properly

Page: 12 > Showing page 1 of 2
Author
Dimitris
Super Member
  • Total Posts : 299
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
2018/09/14 02:16:20 (permalink)
0

ADC dispic33 doesnt work properly

I'm trying to read a sensor PT1000. i'm using XC16 with DSPIC33FJ64GP206A.
The problem is that i'm getting wrong resolution in my output.
 
   
#include "mcc.h"


int ADC_GetConversion(unsigned char channel);
void A2DInit(void)
{
    TRISBbits.TRISB4 = 1; 
    AD1CON1bits.ADON = 0;
    AD1PCFGH = 0xFFFF;
    AD1PCFGL = 0xFFFF;
    
       
    AD1PCFGLbits.PCFG4 = 0; 
   
            
    AD1CON1=0;
    AD1CON2 = 0;
    AD1CON3 = 0;
    AD1CHS0 = 0; 
    
    AD1CON1bits.ADON = 1;
}
int16_t main(void) {
    
    SYSTEM_Initialize();
    RS485_IO=HIGH;
    A2DInit();
    
    while(1)
    {
        
        char txt[44]="";
        sprintf(txt,"%d\r",ADC_GetConversion(4));
        Eusart2_Write(txt);
       __delay_ms(500);
      
      

      
    }
}


 int ADC_GetConversion(unsigned char channel)
{
   
     AD1CHS0 = channel; // Select the requested channel
     __delay_us(10); 
    AD1CON1bits.SAMP = 1; // Start sampling
    __delay_us(10); 
    AD1CON1bits.SAMP = 0; // Start Converting
    while (!AD1CON1bits.DONE); 
    return ADC1BUF0;
    
    
}

 
And here is my output
1023
910
896
891
881
881
880
880
880
865
867
864
864
864
864
864
847
845
844
847
839
835
833
832
832
832
832
832
832
832
832
817
816
816
816
816
809
799
799
799
799
799
799
799
797
796
796
792
792
791
790
787
785
783
783
782
781
780
778
777
778
775
775
773
773
771
770
769
768
768
768
768
768
764
761
760
760
755
755
755
753
753
752
752
752
752
752
743
743
1023
1023
1023
908
899
896
880
880
880
867
871
865
864
864
864
864
864
864
847
844
844
839
839
833
835
832
833
832
832
832
832
832
819
817
816
816
816
807
799
799
799
799
799
799
799
798
796
793
796
792
792
787
788
783
783
783
782
781
780
779
778
775
776
775
775
772
771
769
768
768
768
768
768
768
764
760
760
760
760
755
754
752
752
752
752
752
752
743
752
742
742
739
739
737
737
736
736
736
736
736
736
736
736
736
719
719
719
716
716
711
711
711
708
707
707
707
704
704
704
704
704
704
704
696
697
696
696
692
689
689
688
1023
1023
1023
911
899
896
889
882
880
880
871
871
867
864
864
864
864
864
847
847
847
846
839
839
839
835
833
832
832
832
832
832
832
832
819
817
817
812
813
812
799
799
799
799
799
799
799
796
795
793
793
792
789
787
783
783
783
782
783
780
779
778
775
775
775
773
773
771
770
771
769
768
768
768
768
?1023
906
897
?1023
911
897
888
?1023
911
899
896
887
882
881
880
871
871
865
864
864
864
864
864
847
846
846
846
847
838
839
832
832
832
832
832
832
832
832
819
817
816
816
812
799
799
799
799
799
799
799
798
798
796
793
792
792
790
787
786
783
783
783
782
782
780
779
777
775
775
773
772
771
770
769
769
769
768
768
768
768
761
761
760
760
758
755
753
753
752
752
752
752
752
743
743
743
740
739
737
737
736
736
736
736
736
736
736
736
736
736
736
736
736
736
719
719
719
718
716
716
711
711
711
711
711
711
707
707
707
705
704
705
704
704
704
704
704
704
704
704
704
704
704
696
704
696
696
691
691
689
690
689
688
688
688
688
688
688
688
671
683
671
671
671
671
671
671
671
671
671
671
671
671
671
671
671
671
671
670
671
670
669
668
669
668
667
667
667
665
665
664
665
664
664
664
663
662
662
660
661
659
659
658
655
655
661
655
655
655
655
655
655
654
655
654
654
652
653
652
652
652
651
649
651
650
649
649
647
648
647
647
647
647
647
647
647
645
646
645
646
644
644
644
643
643
643
643
643
642
641
642
642
640
641
640
641
640
640
640
640
640
640
640
639
640
637
640
637
640
636
640
636
636
640
636
637
632
636
632
633
632
636
636
633
632
632
633
632

 
My resolution begins from 1023 and decreasing always
If i will disconnect sensor it doesnt make any change in my resolution.
Is there any register problem?
 
#1
du00000001
Just Some Member
  • Total Posts : 2175
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/14 12:12:45 (permalink)
0
Provide your schematics!
(I assume that you know next-to-nothing about PT1000 but want to make sure.)

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#2
Dimitris
Super Member
  • Total Posts : 299
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/16 22:24:35 (permalink)
0
my pic is DSPIC33FJ64GP206A
Here is my configuration bits
 
    

#pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_FLASH // Boot Segment Program Flash Code Protection (No Boot program Flash segment)
#pragma config RBS = NO_RAM // Boot Segment RAM Protection (No Boot RAM)

// FSS
#pragma config SWRP = WRPROTECT_OFF // Secure Segment Program Write Protect (Secure segment may be written)
#pragma config SSS = NO_FLASH // Secure Segment Program Flash Code Protection (No Secure Segment)
#pragma config RSS = NO_RAM // Secure Segment Data RAM Protection (No Secure RAM)

// FGS
#pragma config GWRP = OFF // General Code Segment Write Protect (User program memory is not write-protected)
#pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected)

// FOSCSEL
#pragma config FNOSC = PRIPLL // Oscillator Mode (Primary Oscillator (XT, HS, EC) w/ PLL)
#pragma config IESO = OFF // Two-speed Oscillator Start-Up Enable (Start up with FRC, then switch)

// FOSC
#pragma config POSCMD = HS // Primary Oscillator Source (XT Oscillator Mode)
#pragma config OSCIOFNC = OFF // OSC2 Pin Function (OSC2 pin has clock out function)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Both Clock Switching and Fail-Safe Clock Monitor are disabled)

// FWDT
#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config WDTPRE = PR128 // WDT Prescaler (1:128)
#pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog timer always enabled)

// FPOR
#pragma config FPWRT = PWR128 // POR Timer Value (128ms)

// FICD
#pragma config ICS = PGD2 // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is Disabled)

 
 
 
post edited by Dimitris - 2018/09/17 04:01:57

Attached Image(s)

#3
PStechPaul
Super Member
  • Total Posts : 2063
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/16 23:30:41 (permalink)
0
You show only a wire labeled UPT1000, but no details on how it connects to the sensor, or details of the sensor itself. What I found indicates it might be a 1000 ohm PTC RTD, maybe:
 
http://www.thermometricscorp.com/pt1000
 

https://en.wikipedia.org/wiki/Resistance_thermometer
 

 

 
#4
Dimitris
Super Member
  • Total Posts : 299
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/16 23:36:06 (permalink)
0
My pt1000 has only two wires
Here is the table https://www.vdhproducts.c...s/2015/01/sm8000en.pdf
#5
PStechPaul
Super Member
  • Total Posts : 2063
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/16 23:42:34 (permalink)
0
Then you can just use a 1k pull-up to Vdd and read the voltage on the RTD to GND. You can then calculate the resistance, and use a look-up table or formula to derive temperature.

 
#6
Dimitris
Super Member
  • Total Posts : 299
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 00:18:29 (permalink)
0
My code for reading adc is right?
#7
PStechPaul
Super Member
  • Total Posts : 2063
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 00:24:49 (permalink)
0
I have no experience with dsPIC33, but it looks OK, and the readings you were getting look like normal ADC values that you might get with the ADC pin disconnected (floating). It starts at maximum (1023) and then drifts toward 1/2 Vref (512).

 
#8
Dimitris
Super Member
  • Total Posts : 299
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 00:54:40 (permalink)
0
Also my resolution is wrong if i have connected my pt1000, my resolution step is 96. It is very small resolution. I need to change it somehow. What registers need to change?
#9
qhb
Superb Member
  • Total Posts : 7526
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 00:57:43 (permalink)
0
I think you are mis-using the word "resolution".
Do you really mean "ADC reading" ?
#10
PStechPaul
Super Member
  • Total Posts : 2063
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 01:13:05 (permalink) ☼ Best Answerby Dimitris 2018/09/17 06:01:19
4.5 (2)
If you use a 1k pull-up with a PT1000 RTD, you should read about 512 for temperature of 25C. A 10k pull-up will give you about 1023/11 = 93.

 
#11
du00000001
Just Some Member
  • Total Posts : 2175
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 01:45:21 (permalink)
0
It might help if you gave us the whole schematics of the attachment of the PT-1000 - including connections to supplies, any filters etc.
'til to the point where the signal connects to the microcontroller's pin.
 
BTW: Could it be your microcontroller is periodically resetting? The list of values given in the initial posting might indicate that.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#12
Dimitris
Super Member
  • Total Posts : 299
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 01:49:31 (permalink)
0
It looks like it is stack in same step. It changes very slow.
Should i set  _SAMC and _ADCS register for working better?
 
 
post edited by Dimitris - 2018/09/17 01:51:12

Attached Image(s)

#13
qhb
Superb Member
  • Total Posts : 7526
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 01:52:46 (permalink)
0
Are you reading the replies from PStechPaul?
 
#14
Dimitris
Super Member
  • Total Posts : 299
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 02:00:48 (permalink)
0
Yes i read it why?
#15
qhb
Superb Member
  • Total Posts : 7526
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 02:09:33 (permalink)
0
He pointed out that 10k is too big!
 
#16
Dimitris
Super Member
  • Total Posts : 299
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 02:14:32 (permalink)
0
I dont think that he means something like that. Also with 1k, can i catch temperatures from 0 till 300 celsius?
post edited by Dimitris - 2018/09/17 02:19:37
#17
qhb
Superb Member
  • Total Posts : 7526
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 02:24:41 (permalink)
0
dimis1989
I dont think that he means something like that.

Why not?
 

Also with 1k, can i catch temperatures from 0 till 300 celsius?

Yes.
Do you understand ohms law?
Have you read the datasheet for your sensor?
Have you tried measuring the voltage across your sensor with a voltmeter?
 
#18
Dimitris
Super Member
  • Total Posts : 299
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 02:32:22 (permalink)
0
if temp 25 is 512 then temp 50  will be 1024. Right?
My read is like it has stacked. and always showing me the same value. 
post edited by Dimitris - 2018/09/17 02:46:28
#19
qhb
Superb Member
  • Total Posts : 7526
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: ADC dispic33 doesnt work properly 2018/09/17 02:39:22 (permalink)
0
Wrong.
You seem to be just guessing values rather than reading datasheets and working out how this all works.
 
Read post#11 again.
If you don't understand how Paul calculated those two values, then you are just flailing around in the dark.
 
post edited by qhb - 2018/09/17 02:43:30
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2018 APG vNext Commercial Version 4.5