Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Moved] dspic30f2010 External oscillator

Status
Not open for further replies.

Jean-Pierre du Plessis

Newbie level 6
Joined
Dec 6, 2010
Messages
11
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,398
Hi,
I realy need help with a external oscillator crystal. I added a 20MHz crystal to the dspic. I tried setting my configuration bits manualy and in code. The OSCCON register showed the complete switching between clock sources. The correct bits are set. This is my switching code.

Code:
void InitCLK (void)
{
 __builtin_write_OSCCONH(0x02);
 __builtin_write_OSCCONL(0x1);
 while (OSCCONbits.COSC != 2);
return;
}						//End of clock initialization

But its seems when I flash a LED with the external crystal running a lot slowwer than with the FRC.
Tomorrow I will go out and buy an 10MHz crystal and try PPL mode.

Please help me?
 
Last edited by a moderator:

Re: dspic30f2010 External oscillator

Firstly, have you reviewed the all pertinent Erratas to see if there are any relevant issues for devices silicon rev?

Have you attempted to configure the proper Configuration Register Bits, setting the oscillator to HS mode, to utilize the external crystal on powerup, rather than switch clock sources during runtime?

Also ensure you have disabled the PLL.

If the new oscillator should fail the device will revert to the Internal RC Oscillator.

Are you using an appropriate pair of capacitors with the crystal? What value?
 

Re: dspic30f2010 External oscillator

I agree with BigD, sounds like the chip's gone into internal-32k-frc mode if there's a "slow clock" symptom... Try disabling the "failsafe" oscilator and see if that stops the LEDs blinking at all, then the oscilator side has to be working for anything to happen....
Often, touching fingers on the crystal-pins will spark some form of result, in which case check the capacitors... Try and keep it all "close to the chip" too, a nice short ground to the (~10pf) cap-pair-low-side...
Keep your confidence up, once it's done you've seen yourself get it going you'll make them all work 1st time and is often a slight hurdle... I can now successfully solder the crystal/caps direct to the PIC and 100% working everytime, you'll be ok :)
NEAL

Cool,
NEAL
 

Re: dspic30f2010 External oscillator

Thank you for the advise. This morning I went out and bought a 10MHz crystal, and read all the application notes on crystals from microchip. I was looking for the size of the two capasitors, but coudnt find it. At the end I added two 10pF as mentiond by LightHiodeDesign and started the pic on the external crystal by setting the configuration bits manualy in MPLAB. And now it works. I previously used 33nF caps, maybe it was to large.

Thanks for the help guys.

I am building a two axis inverted pendulum, so if I need help with the coding I will post back here.
 
Re: dspic30f2010 External oscillator

Can someone please help me. I am using a dsPIC30f2010. I am trying to get the ADC to work. My goal is to use AN0 and AN1 as voltage reference and use AN2 and AN3 as inputs. But it failed. I simplified my code to try and use AN0 – AN3 as inputs just for testing but can’t get it to work. What happens is. If I read ADCBUF0 and ADCBUF1 it gives me the same value of AN0. And if I read ADCBUF2 and ADCBUF3 it gives me the value of AN1. But no buffer has the value for AN2 and AN3. I know I went wrong with my setup but can’t figure out where. So if someone can help me to read AN2 and AN3 with AN0 and AN1 as reference. Maybe I am reading the wrong buffers. This is my code.
This is how I test to see if the value of the buffer change, I connect a pod to the AN pin. And switch on a LED on RB4 if the Buffer value is higher than 500.

Code:
getADC();
 if (ADC6value >= 500)
  PORTBbits.RB4 = 1;
 else
  PORTBbits.RB4 = 0;

This it the function getADC()

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
void getADC (void)
{   Delayms(10);
    ADCON1bits.SAMP = 0;            // Start Conversion
    while(!ADCON1bits.DONE);        // Wait for convert 
    ADC1value = ADCBUF0;
    ADC2value = ADCBUF1;
    ADC3value = ADCBUF2;
    ADC4value = ADCBUF3;
    ADCON1bits.DONE = 0;
    
return;
}




This is the ADC setup

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void enableADC (void)
{
    ADCON1bits.ADON = 0;        //ADC Module is off
    ADCON3bits.ADCS = 2;        // TAD = TCY*(ADCS + 1); Tcy = 25ns; Min TAD = 75ns
        ADCON1bits.FORM = 0;        // Integer
    ADCON1bits.ADSIDL = 0;      //Discontinue module in idle mode
    ADCON1bits.SSRC = 7;        // Automatic Conversion Sequence
    ADCON1bits.SIMSAM = 1;      //Samples multiple channels in sequence
    ADCON1bits.ASAM = 1;        // Auto sampeling, after last sample
    ADCON2bits.VCFG = 0;        // VrefH = AVdd / VrefL = AVss
    ADCON2bits.CSCNA = 1;       //Scan inputs CH0+ 
    ADCON2bits.CHPS = 3;        // Channel CH0 CH1 CH2 conversance
    ADCON2bits.SMPI = 0;        // Increments the DMA address after completion of every sample/conversion operation
    ADCON2bits.ALTS = 0;        //Always use MUX A input multiplexer
    ADCHSbits.CH0SA = 0;
    ADCHSbits.CH123SA = 0;  
    ADCON3bits.ADRC = 0;        // ADC Clock Derived from System Clock
    ADCON3bits.SAMC = 1;        // Auto Sample Time bits TAD
    ADCSSLbits.CSSL0 = 1;       //sCAN INPUT PINS
    ADCSSLbits.CSSL1 = 1;       //sCAN INPUT PINS
    ADCSSLbits.CSSL2 = 1;       //sCAN INPUT PINS
    ADCSSLbits.CSSL3 = 1;       //sCAN INPUT PINS
    ADCON1bits.ADON = 1;        // Turn ADC on
    ADCON1bits.SAMP = 1;        //Start sampeling
return;
}



O and my pins are set as analogue input. Please see if you can help.
 
Last edited by a moderator:

Re: dspic30f2010 External oscillator

I've got some code you can have that does a similar job, but no external references.. There's all sorts in here but you might be able to pick off some good bits.... I'd just got to DSPIC's when I started something else, but MicroChip-Samples have let me have several DSPIC33's to trial so I'll be asking your advice once you've mastered everything :-D
NEAL

Code:
void __attribute__((__interrupt__)) _ADCInterrupt(void)
{

	iAdPlace++;
	iAdPlace&=255;

	unsigned int ADCVoltage2,ADCVoltage;
        int i = 0;
//       	GraphicsHaveChanged=1;	
		unsigned int iPos =0;
		unsigned int* iBuff ;
		iBuff = & ADCBUF0;
		for(iPos=0;iPos<SamplesPerInt;iPos++)				
		{
				ADCVoltage = (ADCVoltage >>1) & 0xff;
				ADCVoltage += 0xff & (((unsigned int)(*(iBuff+(iPos<<1))))>>2);
				
		}
//	GraphicsSpace[iAdPlace][0]= iNT3++; //~(BYTE) ADCVoltage ;
	IFS0bits.ADIF=0;	
	return;	

}

static void SetupADC()
{
	return;
	if(0)
	{
		//return;
		ADPCFG=0b1111111111011;	// Only AN12 in use.	
		TRISBbits.TRISB2=1; // Definately Input!!! // should be ok already but........
		
				//		0b11100100          // Off, Auto sample start, auto-convert	
		ADCON1 = 0b0010000001000100  ;	// Lots of stuff
		ADCON1bits.FORM1 = 0x0; 
		ADCON1bits.FORM0 = 0x0;   
		ADCON2 = 0;               // AVdd, AVss, int every conversion, MUXA only
		ADCON2bits.BUFM=0;
		ADCON3 = 0b1111111111111111;          // 31 Tad auto-sample, Tad = Sysclock;
		ADCON3bits.SAMC=0x0f;	// Sample for 15 Clocks
		ADCON3bits.ADCS=0x3f;	// use 64 clocks to measure
		ADCON3bits.ADRC=0;
		ADCON2bits.SMPI=SamplesPerInt;
		ADCSSL = 0x0000;
		ADCHSbits.CH0NA=1;
		ADCHSbits.CH0SA=0;
		//AD1CHS=0xCC;
	
	
		ADCON1bits.SAMP=0;
//		ADCON2bits.CSCNA=1;
		ADCON1bits.ASAM=1;

		
		ADCON1bits.ADON=1;
	}
  ADPCFG = 0xFFFF ^ 8;        //2nd channel is sampled and coverted
  ADCON1 = 0x0040;        //ADC off, output_format=INTEGER
                          //Timer 3 starts convesion
ADCON1bits.SSRC = 0b111;	
  ADCHS  = 0x0002;        //Connect RB2 on AN2 as CH0 input
  ADCSSL = 0;             //No scan
  ADCON3 = 0x0F00;        //TAD = internalTCY
                          //Sample time ends with timer 3 clock
	IFS0bits.ADIF=0;	
	IEC0bits.ADIE=1;
ADCON1bits.ASAM = 1;
		ADCON1bits.ADON=1;
	ADCHSbits.CH0SA=1;
}

static void SetupTimer3()
{
	T2CONbits.T32 = 0;	// Use t2 as a separate 16bit timer, 16bits for t3, 
//	T3CONbits.T32 = 0;	// Use t2 as a separate 16bit timer, 16bits for t3, 
	T3CONbits.TCKPS=0b11;	// pre-scaler, only tick once per 4 "clocks"
	T3CONbits.TCS=0;	// internal clock
	T3CONbits.TON=1;	
	IEC0bits.T3IE=1;
	IFS0bits.T3IF=0;

	PR3   = 0x0080; 
}
static void SetupTimer2()	// Screen update timer....
{
	T2CONbits.T32 = 0;	// Use t2 as a separate 16bit timer, 16bits for t3, 
//	T3CONbits.T32 = 0;	// Use t2 as a separate 16bit timer, 16bits for t3, 
	T2CONbits.TCKPS=0b11;	// pre-scaler, only tick once per 4 "clocks"
	T2CONbits.TCS=0;	// internal clock
	T2CONbits.TON=1;	
	IEC0bits.T2IE=1;
	IFS0bits.T2IF=0;

	PR2   = 0x400; 
}
 

Re: dspic30f2010 External oscillator

Thanks for the reply. I got it working with some help. I started it with 4 ADC working. When I tried an external voltage ref of 5V it doesnt want to work so I am just using the internal Vref. Ask if you need help, maybe I can help.
 
Re: dspic30f2010 External oscillator

Thank you :) I'd "just got to the point of filters" when I got distracted with some other stuff.... I like the DSPIC30 in 40pin form, big voltage range and lots of legs, my kinda thing... I'll be in touch mate, when I get the samples DSPIC33's setup I want to do some audio processing fun if I can ask of you then my-duck... :)

Many thanks, I like BIG chips, but am just learning SMD...
www.LightDiodeDesigns.co.uk/images/fredtemp/SMD_Matrix
:-D All faired well at the olympics I hoped :)
0bNeal
 

Re: dspic30f2010 External oscillator

Hi can someone please help me. I changed my project. I am using all 6 ADC inputs. An internal volatage refrance. At the moment it is posible to sample and convert 4 of the 6 inputs. I sampling all 4 CH of the adc and then converting it. This is my adc setup code and adc reading code.

Code:
void enableADC(void) {
    ADCON1bits.ADON = 0;            //ADC Module is off
    ADCON3bits.ADCS = 2;            // TAD = TCY*(ADCS + 1); Tcy = 25ns; Min TAD = 75ns
    ADCON1bits.FORM = 0;            // Integer
    ADCON1bits.ADSIDL = 0;          //Discontinue module in idle mode
    ADCON1bits.SSRC = 7;            // Automatic Conversion Sequence
    ADCON1bits.SIMSAM = 1;          //Samples multiple channels in sequence
    ADCON1bits.ASAM = 0;            // Auto sampeling, after last sample

    ADCON2bits.VCFG = 0;            // VrefH = AVdd / VrefL = AVss
    ADCON2bits.CSCNA = 0;           // Scan inputs CH0+
    ADCON2bits.CHPS = 2;            // Channel CH0 CH1 CH2 conversance
    ADCON2bits.SMPI = 0;            // Increments the DMA address after completion of every sample/conversion operation
    ADCON2bits.ALTS = 0;            // Always use MUX A input multiplexer
    ADCON2bits.BUFM = 0;

    ADCHSbits.CH0SA = 3;            //Channel 0 Positive Input Select for MUX A Multiplexer Setting bits
    ADCHSbits.CH123SA = 0;          //Channel 1, 2, 3 Positive Input Select for MUX A Multiplexer Setting bit
    ADCHSbits.CH0NA = 0;            //Channel 0 Negative Input Select for MUX A Multiplexer Setting bit
    ADCHSbits.CH123NA = 0;          //Channel 1, 2, 3 Negative Input Select for MUX A Multiplexer Setting bits

    ADCON3bits.ADRC = 0;            // ADC Clock Derived from System Clock
    ADCON3bits.SAMC = 1;            // Auto Sample Time bits TAD

    ADCON1bits.ADON = 1;            // Turn ADC on
    ADCON1bits.SAMP = 1;            //Start sampeling
    return;
}


    ADCON1bits.DONE = 0;
 
        ADCON1bits.SAMP = 1;                // Start Conversion
        while (!ADCON1bits.DONE);           // Wait for convert
        Nop();

My question is how do I sample all 6 inputs and convert them to go and read them out of the buffers. I tried using the example on page of the refrance manual. I am not sure how to use the interupt bit. When it will be set. Please help me.
 

Re: dspic30f2010 External oscillator

This is what my interrup looks like for a PIC24HJ in similar circumstances....
Code:
void __attribute__((__interrupt__,psv_auto)) _ADC1Interrupt(void) 
		
{
		
        int i = 0;
       	
		unsigned int iPos =0;
		unsigned int* iBuff ;
		iBuff = &ADC1BUF0;
		for(iPos=0;iPos<=SamplesPerInt;iPos++)				
		{
				ADCVoltage = (ADCVoltage >>1) & 0xff;
				ADCVoltage = 0xffff & (((unsigned int)(*(iBuff+iPos)))>>1);
		}	
		
		
 		
 		
	
		IFS0bits.AD1IF=0;
		IFS0bits.AD1IF=0;
	
		
}

I think will be similar....
Cool, Back on track!
NEAL
 

Thanks for the reply. I got it working, I made an error in the setup of the ADC. I have another question. I am settin my ADC to fill the upper half of the 16 bit regester. How can I only use the upper 8 bits to work with.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top