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

dspic33fj12mc202 getting reset when clock is added for adc

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



Joined: 03 Feb 2012
Posts: 29

View user's profile Send private message

dspic33fj12mc202 getting reset when clock is added for adc
PostPosted: Sat Apr 20, 2013 6:19 am     Reply with quote

Hai ....

I have programmed the dspic33fj12mc202 microcontroller and placed the crystal of 20 MHz and when IO operation,LCD is done the controller is working fine. When adc code is included i.e

setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_DIV_2 | ADC_TAD_MUL_2);

while(TRUE)
{
SET_ADC_CHANNEL(0);
delay_ms(10);
man=READ_ADC();
}

it is getting reset continuously and the error displayed if as
1) PC=00056A Interrupt vector for trap adrress error(0xffffff) is above last legal PC ()PC reset to zero.

2) two hardware traps found pending..

And my code is as follows:

Code:
#include <33fj12mc202.h>
#device adc=10
//#FUSES WPRES32                  //Watch Dog Timer PreScalar 1:32
//#FUSES WPOSTS1                  //Watch Dog Timer PostScalar 1:1
#FUSES NOWDT
#FUSES FRC              //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOCKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOJTAG                   //JTAG disabled

#use delay(clock=20000000)//,OSC_INTERNAL)
#use RS232(baud=9600,xmit=pin_B11,rcv=pin_B12,bits=8,stop=1,parity=n,ERRORS,STREAM=PC)
                                             
#byte    PORTA  = 0x02C2
#byte    PORTB  = 0x02CA
#include<float.h>                                                   
#include<math.h>
#include<stddef.h>                       
#include<string.h>
#include<stdlib.h> 

VOID init_io()                                   

  set_tris_a(0x0001);
  set_tris_b(0x0000);   
  }

#separate                                                     
void main(){                                   
    init_io();                                                                                                   
    delay_ms(10);                                 
                                                                                                                   
    setup_adc_ports(sAN0);
   setup_adc(ADC_CLOCK_DIV_2 | ADC_TAD_MUL_2);
                                                                                     
while(TRUE)                                                 
{   
int16 i;
output_high(PIN_B6);
output_high(PIN_B7);

SET_ADC_CHANNEL(0);
 delay_ms(10);
man=READ_ADC();

output_low(PIN_B7);
delay_ms(500);   
}
}



Please reply me with solutions to the above problem...
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 20, 2013 8:16 am     Reply with quote

a quick glance shows...

man=READ_ADC();

yet variable "man" doesn't seem to be previously defined as int16.It may not be the real problem but could cause the compiler to not work right.

also get rid of everything not needed to show the problem,including float.h,math.h,etc.

reduce the code to bare minimum that fails ,it'll be a lot easier to debug.

hth
jay
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