Hot!ADC dispic33 doesnt work properly

Author
Dimitris
Super Member
  • Total Posts : 279
  • Reward points : 0
  • Joined: 2017/11/03 10:29:26
  • Location: 0
  • Status: offline
2018/09/13 23:00:46 (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

4 Replies Related Threads

    andersm
    Super Member
    • Total Posts : 2447
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: offline
    Re: ADC dispic33 doesnt work properly 2018/09/13 23:11:28 (permalink)
    +1 (1)
    The dsPIC33F forum is that way.
    #2
    rodims
    Super Member
    • Total Posts : 1337
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: online
    Re: ADC dispic33 doesnt work properly 2018/09/14 02:41:01 (permalink)
    0
    The thread is continued here:
    https://www.microchip.com/forums/m1068057.aspx#1068057
    Dimitris, you could add this information yourself to avoid confusion generated by double postings
    #3
    Dimitris
    Super Member
    • Total Posts : 279
    • Reward points : 0
    • Joined: 2017/11/03 10:29:26
    • Location: 0
    • Status: offline
    Re: ADC dispic33 doesnt work properly 2018/09/14 02:51:48 (permalink)
    0
    How can i delete this post?
    #4
    rodims
    Super Member
    • Total Posts : 1337
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: online
    Re: ADC dispic33 doesnt work properly 2018/09/14 03:59:19 (permalink)
    0
    You cannot. (and nobody from Microchip will do that for you).
    Always first choose correct forum, then post.
    My comment for you was meant as recommendation for future posts, not this one.

    You can edit (and reduce) a post early to make such errors clear, but chance is good that you add confusion to a thread if you do that now, so just leave it.  The comment "continued here" usually means that this thread is dead. 
     
    having said this, continue here:
    https://www.microchip.com/forums/m1068057.aspx#1068057
    #5
    Jump to:
    © 2018 APG vNext Commercial Version 4.5