View previous topic :: View next topic |
Author |
Message |
ortegahernandes
Joined: 14 Feb 2020 Posts: 23
|
dsPIC33ch128mp506 + read_adc // freeze [resolved] |
Posted: Sat Nov 14, 2020 3:22 am |
|
|
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
|
|
Posted: Sat Nov 14, 2020 3:46 am |
|
|
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
|
|
Posted: Sat Nov 14, 2020 10:20 am |
|
|
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: 19535
|
|
Posted: Sat Nov 14, 2020 1:13 pm |
|
|
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.... |
|
|
|