count problems (16F873A)


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    alejandro_halon's Avatar
    alejandro_halon Guest

    Default count problems (16F873A)

    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...

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    alejandro_halon's Avatar
    alejandro_halon Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    alejandro_halon's Avatar
    alejandro_halon Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    alejandro_halon's Avatar
    alejandro_halon Guest


    Did you find this post helpful? Yes | No

    Default More info

    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.

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Out of curiosity, how stable is the count if you disable interrupts?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  9. #9
    alejandro_halon's Avatar
    alejandro_halon Guest


    Did you find this post helpful? Yes | No

    Default

    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?

  10. #10
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by Bruce; - 11th February 2005 at 16:32.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  11. #11
    alejandro_halon's Avatar
    alejandro_halon Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks a lot for the help! Was VERY usefull. Well, let´s back to work.

    Hasta la vista!
    Alejandro.

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Attached Images Attached Images  
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  2. Can't get COUNT to count
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd March 2009, 23:14
  3. problems with parallel LCD
    By Brown in forum mel PIC BASIC
    Replies: 11
    Last Post: - 12th June 2008, 04:37
  4. Count command
    By hawk72501 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th September 2005, 19:04
  5. count problem
    By servo260 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd December 2004, 15:05

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts