PDA

View Full Version : count problems (16F873A)



alejandro_halon
- 10th February 2005, 21:11
This is my first message, and (of course) I´m having some problems...

I was using the PIC 16F870 to do some low freq counting (like 0 to 600Hz), It was very stable. Last week I need more memory, so I get a 16F873A (4k), recompile the program and the counter becomes VERY unstable.

Exists some diference between the 16f870 and 16f873a?

I´m using 20MHz crystal and a function generator (calibrated) to send the pulses to the pic.

Please, I need some help because I´m lost...

PS: sorry for my TERRIBLE english...

Bruce
- 11th February 2005, 03:20
The "A" series parts are much more sensitive to noise & power spikes than the non A series. Be sure to place a 0.1uF capacitor between Vcc & GND with the cap located as close as possible to the PIC.

mister_e
- 11th February 2005, 05:04
That's true, AND if it's on a bread-board try to remove the capacitor around your crystal... it happen to me in the past. The bread-board do a kinda capacitance load.

alejandro_halon
- 11th February 2005, 08:38
Hi mister_e!

sorry, but I´m not sure if understand. You´re telling me to remove the capacitors (22pf) from crystal to ground?

And yes, it´s on a bread board... And with a 20MHz Crystal... Using a 4MHz (or a 3.57954Mhz) will help?

Tks.



Originally posted by mister_e
That's true, AND if it's on a bread-board try to remove the capacitor around your crystal... it happen to me in the past. The bread-board do a kinda capacitance load.

alejandro_halon
- 11th February 2005, 08:41
the .1uF helps to get a little more stable reading, but not solves the problem. I´m worried about the project is going to be installed on a car, with (a think) a lot of more noise...

Tks.



Originally posted by Bruce
The "A" series parts are much more sensitive to noise & power spikes than the non A series. Be sure to place a 0.1uF capacitor between Vcc & GND with the cap located as close as possible to the PIC.

Bruce
- 11th February 2005, 13:31
The more information you provide, the better your chance of someone here helping you isolate/fix the problem.

Post a few more details like;

How are you counting pulses?
Which I/O-pin are you using?
Power supply?
Config fuse settings?

Post your code - or sections of your code you're having problems with.

alejandro_halon
- 11th February 2005, 13:58
Sure,

PIC: 16F873A (brand new, tested in two units)

The pulses are counted with COUNT, the code is:

Count FREQ, 400, bPulsos

Where:

bPulsos is a byte var. The frequenci is very low, at max about 600 Hz. And "FREQ" is PORTB.0 (I´ve tried PORTC.4 and PORTC.3 also).

The basic config of the PIC is:

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

DEFINE LCD_DATAUS 50
DEFINE LCD_COMMANDUS 2000

DEFINE OSC 20 'MHz

DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3 ' 6uS para leitura ADC (FRC)
DEFINE ADC_SAMPLEUS 50 ' sample de 50 microsegundos

DEFINE INTHAND tmrInt
DEFINE NO_CLRWDT 1


TRISA = %11111111
TRISC = %11110111
TRISB = %00000001
ADCON1 = %10000010
OPTION_REG = %00001000
INTCON = %11000000
PIE1 = %00000010
T2CON = %01010010

I´m using Timer 2 to count time, by interruption. Also I have 3 reads of ADC (2 x LM35 and 1 potenciometer). An LCD display (16x2) is connected to PORTB.

Supply is a simple AC/DC adapter with 12.7v, regulated with a LM7805. 1000uF at in and 100nF in the out of 7805.

The pulses are generated with a function generator, very stable and calibrated with a frequencimeter. I´m using 200Hz to test the program.


This circuit must run in a car using the car battery as a power supply.

Also build a simple "low-pass" passive filter for the signal in (A 1uF and a 1,2k resistor). This cut freq about 900Hz, but not solve the problem.

All ADC readings are stable, buttons (3) sometimes don´t work.

The problem is with the count, VERY unstable.

Only for the records: The same program execute PERFECTLY in a 16F870, but 2k is very low.


If need more info, PLEASE let me know.

Thanks in advance.



Originally posted by Bruce
The more information you provide, the better your chance of someone here helping you isolate/fix the problem.

Post a few more details like;

How are you counting pulses?
Which I/O-pin are you using?
Power supply?
Config fuse settings?

Post your code - or sections of your code you're having problems with.

Bruce
- 11th February 2005, 14:55
Out of curiosity, how stable is the count if you disable interrupts?

alejandro_halon
- 11th February 2005, 16:20
Same thing, no diference...

The count becomes better using a high pass filter, with a 470nF and a 12k resistor. This means low freq. noise... like the 60Hz of the 120vAC (in Brazil is 60Hz). Is not 100% stable but working a little more on the filter will be ok (I hope so).

I really don´t know that the 873A was SO sensible to noise. I´ve used the 628A without any problems...


Originally posted by Bruce
Out of curiosity, how stable is the count if you disable interrupts?

Bruce
- 11th February 2005, 16:27
I've noticed a huge difference with pretty much all of the A series.

Run a quick test with a battery power supply. If it works, bingo. There's the problem. You just need better power supply filtration.

Note: If this device will go into an automobile, you're in for a lot more headaches getting rid of power supply & other noise in that environment.

alejandro_halon
- 11th February 2005, 17:11
Thanks a lot for the help! Was VERY usefull. Well, let´s back to work.

Hasta la vista!
Alejandro.

mister_e
- 11th February 2005, 17:18
i did many stuff to go in car. You MUST use a serie resistor (let's say 10Ohms ) an a big capacitor (let's say 1000-2200) + 0.1 uF ceramic + 10-22uF tantalum at the input of the voltage regulator for a better noise regulation/supression. At the voltage regulator output, you MUSt have 0.1uF + 10-22uF tantalum. The PCB MUST have many ground plane + all unused pins of the PIC must be tie to ground OR VCC. AND for sure 0.1uF as close as you can to the PIC.

Most remote starter or car alarm use the above configuration.

Your PIC pin for the pulse count, must have a pull down resistor (4.7K-22K) to avoid "weird reading" In My Tach reading application, i've use the appended circuit without any kind of problem.