go away spammer

Author Topic: How to know if crystal working  (Read 8037 times)

0 Members and 1 Guest are viewing this topic.

Offline PolarisTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
How to know if crystal working
« on: January 11, 2007, 07:52:40 AM »
Hi all

  Pls advise me on this. I had a simple circuit comprising of a microntroller with one of its port connected to a LED + resistor. I had also connected a crystal oscillator of 4MHz as mentioned in the datasheet for the microcontrller that i am using. In the micro controller, i had download a simple program which do simple thing of turning off and on the LED to create a blinking effect. However, when turned on the circuit, the LED just turn on dimly and checking the voltage level at the same output pin, using a multimeter, the voltage stays constant. Inferring from this, it meant the program is not workng?  i am in a fix, am doubting if the crystal is working. Could anyone advise me any simple technique to do a check ( i do not have an oscilloscope) ? or any good advice to dispense? Thanks

Offline Militoy

  • Expert Roboticist
  • Full Member
  • *****
  • Posts: 111
  • Helpful? 0
Re: How to know if crystal working
« Reply #1 on: January 11, 2007, 12:15:04 PM »
A couple of thoughts -

Does your multimeter have a frequency (Hz) scale? A lot of them do, and you may be able to tell if the crystal is operating by looking at your clock pin with the frequency counter setting on your meter. Also - what voltage did you read when you looked at the pin with the dimly-lit LED? Is it possible that the LED actually IS blinking, but at a rate too fast to see, so that it just appears to be lit dimly? Adjusting the flash rate, and/or the on and off times in your code may improve matters. Good luck!

Offline PolarisTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: How to know if crystal working
« Reply #2 on: January 11, 2007, 08:19:35 PM »
A couple of thoughts -

Does your multimeter have a frequency (Hz) scale? A lot of them do, and you may be able to tell if the crystal is operating by looking at your clock pin with the frequency counter setting on your meter. Also - what voltage did you read when you looked at the pin with the dimly-lit LED? Is it possible that the LED actually IS blinking, but at a rate too fast to see, so that it just appears to be lit dimly? Adjusting the flash rate, and/or the on and off times in your code may improve matters. Good luck!

Yes, my multimeter has one, but i think it is limited to 99KHz which is less than the crystal of 4MHz, can i still use it? Can you elaborate further on how to use the multimeter to perform the check, am new to this.

My reading at the o/p pin show ~4.1V and stays quite constant. I did see the glowing/diming of light at the LED(apparent when observing from the top instead of side view of the led) but kinda of dismiss it as fluctuation of voltage(ya i know it contradict my statement that my meter shows a constant voltage reading...*scratching my head*)

I did perform an adjustment to the code to have a 5s interval delay between each blinking on/off, but no difference in output. at present, i am connecting my o/p pin to a 377ohms resistor and follow by a LED and a LED's led to gnd. is this correct?

Offline andreahmed

  • Jr. Member
  • **
  • Posts: 37
  • Helpful? 0
Re: How to know if crystal working
« Reply #3 on: January 11, 2007, 08:29:08 PM »
i were about to suggest doing a delay blink led off and on ,, it seems the crystal is defective or the micro ..

Offline Militoy

  • Expert Roboticist
  • Full Member
  • *****
  • Posts: 111
  • Helpful? 0
Re: How to know if crystal working
« Reply #4 on: January 11, 2007, 10:03:33 PM »
Quote
Yes, my multimeter has one, but i think it is limited to 99KHz which is less than the crystal of 4MHz, can i still use it?

Sometimes a freq counter will still pick up a subharmonic of the frequency it's seeing - it's worth trying to measure, to see if you get anything off the clock pin - but the 99KHz bandwith of your meter may not let you see much.

Quote
i am connecting my o/p pin to a 377ohms resistor and follow by a LED and a LED's led to gnd. is this correct?

That resistor will give you maybe 11mA through the LED - seems a little high, but OK if the LED you're using is rated for that much current.

Do you have a link to the schematic of what you're doing, or if it's just a few components, do you want to describe it? Hopefully, you didn't handle the micro without grounding yourself and your tools, etc., and maybe blasted out the chip!

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: How to know if crystal working
« Reply #5 on: January 12, 2007, 04:36:19 AM »
hi Polaris, if you want to confirm Militoy's first theory that the LED is blinking, just too fast to see (which sounds quite likely to me) you could try the following.
write initialisation code for your microcontroller. don't forget to initialize the pins the LEDs are connected to as output.
in your code, set the output of one pin to on and a 2nd pin to off.
put a loop as the main routine in your code but don't put any real commands in there for now.
program your microcontroller and power it up.

do the pins you configured as outputs have the high (on) and low (off) voltages you expect? if they do then it appears that your micro, other components and configuration section of code work ok. try re programming, swapping the high and low pins round just to confirm.

if the pins both sit at the same voltage as in your troublesome flashing LED example then the problem will be one of the following:
incorrect code. the smallest typo can break everything.
incorrect circuit. i have spent hours before trying to work out why a miswired circuit is not working.
faulty component. so it is probably the least likely explanation but still possible.

let us know a little more:
which microcontroller are you using?
can you draw us a quick diagram of your circuit?
post the code you are uploading to your microcontroller here.

dunk.

Offline Militoy

  • Expert Roboticist
  • Full Member
  • *****
  • Posts: 111
  • Helpful? 0
Re: How to know if crystal working
« Reply #6 on: January 12, 2007, 08:20:25 PM »
Dunk's comments sparked another idea on a way of measuring what the LED may be doing: Even though your meter's frequency range may be too slow to pick up the clock frequency, I'll bet it will be able to tell if the LED is just blinking fast. Try putting the ground (black) lead on ground, and the meter input (red) lead on the output pin with the LED (while it's supposed to be in a "while loop" blinking) - with the meter set on the Hz scale. Do you get any reading?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to know if crystal working
« Reply #7 on: January 12, 2007, 08:27:39 PM »
another idea for measuring voltage from the frequency . . . if the above dont work . . . make a RC circuit! this smooths out the squarewave to an analog voltage that you can read with your multi-meter.

attach the output pin to a 10kohm resistor. then attach the other end of the resistor to a 10uF capacitor. next attach the other end of that capacitor to ground. finally, measure the voltage between the resistor and capacitor . . .

you may have to tweak the cap value though, depending on frequency . . .

Offline PolarisTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: How to know if crystal working
« Reply #8 on: January 16, 2007, 11:15:07 PM »
sorri for this late reply as busy with other things.

my humble LED circuit.



will post my program later of the day.

As recommended, i had tried to program the Pin RA0, Pin RA1, Pin RA2, Pin RA3 as On, Off, On, Off. But seem like all of them when i attached the LED to each of the port, the LED was lit. My 2nd attempt was to experiment with only one Port, Pin RA1, which i modified the program to turn it off forever. The LED did not light.Setting the same port to on, the LED was lit. When i tried to put it more ports in as what i did previously, it did not output as expected. Got to try more of your proposed solution, but a bit tied up.

Offline PolarisTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: How to know if crystal working
« Reply #9 on: January 17, 2007, 07:08:06 AM »
//helloled.c

#ifndef LED_TRIS
#define LED_TRIS  TRISAbits.TRISA1
#endif

#ifndef LED_LATA
#define LED_LATA  LATAbits.LATA0
#endif

#ifndef LED_PIN_RA0
#define LED_PIN_RA0 PORTAbits.RA0
#endif

#ifndef LED_PIN_RA1
#define LED_PIN_RA1 PORTAbits.RA1
#endif


#ifndef LED_PIN_RA2
#define LED_PIN_RA2 PORTAbits.RA2
#endif

#ifndef LED_PIN_RA3
#define LED_PIN_RA3 PORTAbits.RA3
#endif

#ifndef LED_PIN_RA4
#define LED_PIN_RA4 PORTAbits.RA4
#endif

#include <pic18f252.h>

void delay_ms(int ms)
{
int i ;

for(i=0;i <ms;i++);

}
void main()
{

  LED_LATA = 0;

  for(i
  LED_PIN_RA0=0;
  LED_PIN_RA1=0;
  LED_PIN_RA2=0;
  LED_PIN_RA3=0;

  LED_TRIS=0;


 while(1)
 {
   LED_PIN_RA1=0;
   delay_ms(10000);
   LED_PIN_RA1=1;
   delay_ms(10000);
   }

 }

Note:** LED_PIN_RA1 will always be off and never turn ON.

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: How to know if crystal working
« Reply #10 on: January 17, 2007, 10:34:36 AM »
so i only programmed PICs in machine code so i'll let someone else comment on your code.

as for the circuit diagram, is this a typo in your drawing or are you missing a ground connection to pin 8?
also make sure you get a capacitor bettween Vss and Vdd pins, physically nice and close to the chip to reduce any ripple in the power... 0.1uF should be good.

speaking of power, what are you using as a power supply?
batterys are generaly easiest to work with when you are getting started as they give you a nice smooth suppliy.

dunk.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to know if crystal working
« Reply #11 on: January 17, 2007, 01:03:24 PM »
a few problems . . . first your schematic . . .

The LED is connected wrong, as it only works in one direction. The arrow should point to ground. Second, that LED is draining huge amounts of power (which could cause fickleness with your microcontroller, and fry your LED). Connect a resistor (500ohm to like 3kohm) between the LED and ground. and make sure all your grounds are shared and connected . . .

As for your code, Im confused by your typo (you forgot the other half of the for command) :P:

for(i
  LED_PIN_RA0=0;
  LED_PIN_RA1=0;
  LED_PIN_RA2=0;
  LED_PIN_RA3=0;

  LED_TRIS=0;

your delay code will work, but there is a non-guesswork way of doing it. what you want is to initialize timer0. read this:
http://www.societyofrobots.com/programming_timers.shtml

also, you are storing the number 10000 as an 'int ms' for your delay function. but an int cant go higher than 255! change the int to long int. do this for 'int i' as well.

if it still doesnt work after these corrections, repost your schematic/code and we will look at it again . . . these are the obvious fixes . . .  :P

Offline trigger

  • Full Member
  • ***
  • Posts: 115
  • Helpful? 0
  • It's an op amp, not a gun part.
Re: How to know if crystal working
« Reply #12 on: January 17, 2007, 01:04:41 PM »
edit: admin and I posted about the for loop at the same time, disregard my comment then
There are 10 kinds of people in this world: those who can read binary, and those who can't.

Offline PolarisTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: How to know if crystal working
« Reply #13 on: January 19, 2007, 09:50:40 AM »
edit: admin and I posted about the for loop at the same time, disregard my comment then
Thanks for everyone, am still unable to get my LED to blink...Sign...

What is not in the diagram is my simple voltage regulator which delivers 5V.



//helloled.c

#ifndef LED_TRIS
#define LED_TRIS  TRISA
#endif

#ifndef LED_LATA
#define LED_LATA  LATA
#endif

#ifndef LED_PIN_RA1
#define LED_PIN_RA1 PORTA.1
#endif

#ifndef LED_PIN_RA2
#define LED_PIN_RA2 PORTA.2
#endif
#include <18f252.h>

void delay_ms(long ms)
{
long i, test ;
 test = ms;
 for(i=0;i < ms;i++);
}
void main()
{

  LED_TRIS = 0;
  LED_LATA = 0;
  LED_PIN_RA1=0;
 while(1)
 {
   LED_PIN_RA1=0;
   delay_ms(50);
   LED_PIN_RA1=1;
   delay_ms(50);   
  }
}

The output is that the LED connected to RA1 just light up and not blinking. I tried taking out the oscillator, the LED is still lit.what goes wrong here? pls kindly help thanks

Offline JonHylands

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 562
  • Helpful? 3
  • Robot Builder/ Software Developer
    • Jon's Place
Re: How to know if crystal working
« Reply #14 on: January 19, 2007, 10:00:10 AM »
The problem is your delay certainly doesn't delay 50 ms. You are passing in a value which you loop that many times in an empty loop. That loop is probably running in less than 100 micro-seconds, depending on the value of your crystal. At 4 MHz, you're running 1 million machine language instructions per second, and your loop probably generates 5-10 instructions per cycle, which means at best your 50 ms delay is only delaying 500 us.

You need to put a 100x multiplier into your loop. Even then, flashing 20x per second is too fast, you might not see it.

I would do this:

void delay_ms(long ms)
{
long i, test ;
 test = ms * 100;
 for(i=0;i < test;i++);
}

And then change your delay that you're passing in to 500, so it flashes somewhere around once per second. That way you know it works. Then you can calibrate it - it you can post the machine code that your compiler produces for that loop, we can count instructions and know exactly what the factor should be.

- Jon


Offline PolarisTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: How to know if crystal working
« Reply #15 on: January 23, 2007, 10:06:02 AM »
thanks, i had tried that but still could get her working...i had tried to put the output pin RA1 to 0, (turn off)..but the LED is still lit.seriously thinking of rewire the circuit again.. :( :(

Offline PolarisTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: How to know if crystal working
« Reply #16 on: January 23, 2007, 10:07:02 AM »
thanks, i had tried that but still could get her working...i had tried to put the output pin RA1 to 0, (turn off)..but the LED is still lit.seriously thinking of rewire the circuit again.. :( :(

My apology, i meant i still can't get her working..

Offline JonHylands

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 562
  • Helpful? 3
  • Robot Builder/ Software Developer
    • Jon's Place
Re: How to know if crystal working
« Reply #17 on: January 23, 2007, 10:17:59 AM »
Can you post your code again, with the new delay constants, and your attempt to set it to 0?

- Jon

Offline PolarisTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: How to know if crystal working
« Reply #18 on: January 23, 2007, 07:10:52 PM »
Can you post your code again, with the new delay constants, and your attempt to set it to 0?

- Jon



Thanks jon, i will post it later. For now, i posted my circuit spec for questions that were posted to me before.

My simple circuit spec:

microcontroller: PIC 18F252, powered by a DIY simple voltage regulator that output a constant 5V from a 9V alkaline battery.
Oscillator Freq: 4MHz, with two 15pF capacitors.
Compiler: Trying out both CC8E and SDCC. (preferred the former has there is more support)




 


Offline PolarisTopic starter

  • Jr. Member
  • **
  • Posts: 19
  • Helpful? 0
Re: How to know if crystal working
« Reply #19 on: January 24, 2007, 06:45:12 AM »
//helloled.c

#ifndef LED_TRIS
#define LED_TRIS  TRISA
#endif

#ifndef LED_LATA
#define LED_LATA  LATA
#endif

#ifndef LED_PIN_RA1
#define LED_PIN_RA1 PORTA.1
#endif

#ifndef LED_PIN_RA2
#define LED_PIN_RA2 PORTA.2
#endif

#ifndef OSC_CONFIG
#define OSC_CONFIG  OSCCON 
#endif

#include <18f252.h>

void delay_ms(long ms)
{
long i, test ;
 test = ms * 100;
 for(i=0;i < ms;i++);
}
void main()
{
  LED_TRIS = 0;
  LED_LATA = 0;
  LED_PIN_RA1=0;
  OSC_CONFIG = 0b00000001;
 while(1)
 {
   //LED_PIN_RA1=1;
   //LED_PIN_RA2=1;
   LED_PIN_RA1=0;

   //uncomment below to simulate on off pattern
   //delay_ms(500);
   //LED_PIN_RA1=1;
  // delay_ms(500);
   
  }
 
}


After re-wire my circuit, it still doesn't work...and after i reread the spec that comes with the chip, i think i need to configure the chip internal register to enable a particular mode of oscillator. but still can't get working...anyone has any experience with PIC chip? thanks

Offline JonHylands

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 562
  • Helpful? 3
  • Robot Builder/ Software Developer
    • Jon's Place
Re: How to know if crystal working
« Reply #20 on: January 24, 2007, 07:29:40 AM »
You're still looping in your delay routine to ms instead of test.

- Jon

 


Get Your Ad Here

data_list