dsPIC33 ADC hangs

General discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
diver999
Posts: 10
Joined: 02 Aug 2014 11:43

dsPIC33 ADC hangs

#1 Post by diver999 » 17 Aug 2014 09:41

Hi All,
I am migrating a design from 18F4520 to dsPIC33FJ32GS606. Clock is generated by 6MHz crystal.
I have all done EXCEPT reading ADC1. It hangs.
I have taken the demo for the dsPIC33FJ256GP710A. Code is :

Code: Select all

program ADC_Demo;
 
var adc_result : longint;
    sx : string[6];
begin
  // PLL settings
  PLLPRE_4_bit := 0;          // PLLPRE<4:0> = 0  ->  N1 = 2    8MHz / 2 = 4MHz
  PLLPRE_3_bit := 0;          // (must be within 0.8 MHz to 8 MHz range)
  PLLPRE_2_bit := 0;
  PLLPRE_1_bit := 0;
  PLLPRE_0_bit := 0;
  
  PLLFBD :=   38;               // PLLDIV<8:0> = 38 ->  M = 40    4MHz * 40 = 160MHz
                                      // (must be within 100 MHz to 200 MHz range)
  PLLPOST_0_bit := 0;         // PLLPOST<1:0> = 0 ->  N2 = 2    160MHz / 2 = 80MHz
  PLLPOST_0_bit := 0;         // (must be within 12.5 MHz to 80 MHz range)

  ADPCFG := 0xFF00;         // Set PCFG0 as analog input
  UART2_Init_Advanced(9600, 1, 1, 1);  Delay_ms(100);              // Wait for UART module to stabilize

  TRISD := 0;                 // Set PORTD as output
  TRISB := 0xFFFF;
  adc_result := 0;            // Set initial ADC value to zero
  
  ADC1_Init;                  // Initialize ADC module
  Delay_ms(100);

  while TRUE do
  begin
    Uart2_write('.');
    adc_result := ADC1_Get_Sample(5);  // Get ADC value from corresponding channel
//    adc_result := ADC1_Read(5);        // Get ADC value from corresponding channel
    wordtostr(adc_result,sx);
    Uart2_write_text(sx);
    Delay_ms(50);
  end;
end.
Any ideas ? Thanks

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: dsPIC33 ADC hangs

#2 Post by marina.petrovic » 19 Aug 2014 11:10

Hi,

Unfortunately, I do not have the same hardware that you use, so I am not able to test your project.
Please, can you explain me a little bit more where the problem occurs?
Whether you have some data transferred over UART?

Did you tried to use some other channel?

Best regards,
Marina

diver999
Posts: 10
Joined: 02 Aug 2014 11:43

Re: dsPIC33 ADC hangs

#3 Post by diver999 » 19 Aug 2014 12:06

Thanks

The Uart displays one '.' - so it goes through Init, but hangs on the first ADC1_read (or ADC1_get_sample)
I have tried this on many inputs (at least up to 6)

R

diver999
Posts: 10
Joined: 02 Aug 2014 11:43

Re: dsPIC33 ADC hangs

#4 Post by diver999 » 22 Aug 2014 16:35

Hi Marina

Do you have any comments ?

Thanks

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: dsPIC33 ADC hangs

#5 Post by jpc » 22 Aug 2014 21:31

did you try to use a word variable for your adc_result? i do not understand why you declare it as longint and then use a wordtostr conversion, maybe your problem is there.
Au royaume des aveugles, les borgnes sont rois.

diver999
Posts: 10
Joined: 02 Aug 2014 11:43

Re: dsPIC33 ADC hangs

#6 Post by diver999 » 22 Aug 2014 22:05

I have tried many, many things. It always hangs on adc1_read or adc1_get_sample. Nothing to do with declaration or conversion. Have you been able to test this ?
Thanks

diver999
Posts: 10
Joined: 02 Aug 2014 11:43

Re: dsPIC33 ADC hangs

#7 Post by diver999 » 09 Sep 2014 19:10

Hi !
I have now tried several different chips and the ADC always hangs on dsPIC33FJ32GS606.
Please could you post some reference code so that I can try to debug this ?
It is really critical for my project now.
Many thanks

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: dsPIC33 ADC hangs

#8 Post by Dany » 09 Sep 2014 19:57

Hi, the ADC part of the dsPIC33FJ32GS606 seems to be very complicated. It apparently has 2 "SAR's" (which means I think 2 ADC convertors). I assume that "ADC1_Init;" will initialise the upper one in figure 2-22 of the datasheet, I do not know if this is true however.

I also do not know which analog inputs you have tried, but as far as I can see the upper SAR (assumed by me to be ADC1) can only be used for "EVEN" numbered analog inputs, and the lower one (I assume this is ADC2) for the ODD numbered inputs.

If above is true then you should use "ADC2_Init" (and ADC2_Read) if you want to use ADC channel 5.
If of course you did try already an "even" input, then it should have worked with ADC1_Init...

But: "ADC2_Init" gives an error: not declared...
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

diver999
Posts: 10
Joined: 02 Aug 2014 11:43

Re: dsPIC33 ADC hangs

#9 Post by diver999 » 10 Sep 2014 08:41

Thanks Dany
I have tried all inputs from 0 to 7 - all the same.
Do you have experience of this PIC ?

microElektronika team :
1. Is it possible to look at this ?
2. Also, please can you post some reference code and register/bit definitions so I can try to code an alternative by poking registers ?

Many thanks for all your urgent help

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: dsPIC33 ADC hangs

#10 Post by Dany » 10 Sep 2014 10:31

diver999 wrote:Thanks Dany
I have tried all inputs from 0 to 7 - all the same.
Ok. :D
diver999 wrote:Do you have experience of this PIC ?
No, I have not, just trying to help.. :oops: Without success... :?
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal PRO for dsPIC30/33 and PIC24 General”