CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

dsPIC33ch128mp506 + read_adc // freeze [resolved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ortegahernandes



Joined: 14 Feb 2020
Posts: 23

View user's profile Send private message

dsPIC33ch128mp506 + read_adc // freeze [resolved]
PostPosted: Sat Nov 14, 2020 3:22 am     Reply with quote

Hello, good morning everyone.

I have a card with a dsPIC33ch128mp506.

After a lot of "fighting" I managed to activate the two nuclei and, they are almost fully functional, just missing the WDT and the analog part.

The problem I came to ask here is that the following is happening.

When I'm going to do an analog reading the PIC freezes.
Example:
Code:

int value;
delay_ms (250);
value = read_adc (); // it freezes here
output_toggle (Led_1);

Already put on the main line both in Timer 1, in both it freezes.

CCS version 5.093


Last edited by ortegahernandes on Sat Nov 14, 2020 10:21 am; edited 1 time in total
ortegahernandes



Joined: 14 Feb 2020
Posts: 23

View user's profile Send private message

PostPosted: Sat Nov 14, 2020 3:46 am     Reply with quote

I made a simplified example of how it freezesL
Code:

#include <33CH128MP506.h>
#device ADC=10
#use delay(crystal=32MHz)
#build (stack = 512)
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES CKSNOFSM                 //Clock Switching is enabled, fail Safe clock monitor is disabled
#FUSES HS
//#FUSES PR
//#fuses XTGAIN3 
                                //Crystal output drive set for 24-32 MHz crystals
#define    Led_2       Pin_A4
#define    Led_1       Pin_D12


void main()
{
   int valor;
   setup_adc_ports(sAN2);
   setup_adc(ADC_CLOCK_SYSTEM | ADC_CLOCK_DIV_64 | ADC_WARMTIME_16 | ADC_SHARED_CLOCK_DIV_2 | ADC_SHARED_TAD_MUL_2);


   while(TRUE)
   {
     output_toggle(led_1);
     delay_ms(250);
     output_toggle(led_1);
     delay_ms(250);
     output_toggle(led_1);
     delay_ms(250);
     set_adc_channel(2);
     valor = read_adc();    // freeze
     delay_ms(250);
     output_toggle(led_2);
   }

}


Is there any way to trigger the ADC and read the buffer directly from the registers?

Does anyone have an example?
ortegahernandes



Joined: 14 Feb 2020
Posts: 23

View user's profile Send private message

PostPosted: Sat Nov 14, 2020 10:20 am     Reply with quote

I've solved the problem ......

if someone has the same problem ...

the parameter was missing:

"ADC_ENABLE_SHARED_CORE"

Code:
setup_adc(ADC_CLOCK_SYSTEM | ADC_CLOCK_DIV_2 | ADC_WARMTIME_32768 | ADC_SHARED_CLOCK_DIV_2 | ADC_SHARED_TAD_MUL_513|ADC_ENABLE_SHARED_CORE);
[/code]

Last edited by ortegahernandes on Sat Nov 14, 2020 7:42 pm; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Sat Nov 14, 2020 1:13 pm     Reply with quote

Well done.
I must admit I stated looking through it, and the only thing that could cause
the hang, was that the ADC was not actually running, but didn't spot
what was stopping it.... Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group