Author Topic: Small package decade counter?  (Read 2589 times)

0 Members and 1 Guest are viewing this topic.

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Small package decade counter?
« on: March 30, 2019, 06:32:20 am »
Does anyone know of a small package decade counter? I need to divide a 100 Hz signal by 10. The smallest units I can find are in SOIC-14 or SOIC-16.

Nexperia has a new line of fixed division counters, the 74AHC1G421x series, but unfortunately no divide by 10.
 

Offline DC1MC

  • Super Contributor
  • ***
  • Posts: 1886
  • Country: de
Re: Small package decade counter?
« Reply #1 on: March 30, 2019, 06:45:59 am »
GreenPak SLG46536V 50c in STQFN-14 (2.0 x 2.2 mm)
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13119
Re: Small package decade counter?
« Reply #2 on: March 30, 2019, 06:57:46 am »
If you don't want to go down the GreenPak road, you could program a PIC10F part in SOT23-6 or DFN-8 (2.0 x3.0 mm)  to do the job (PIC10F200 if you can tolerate the propagation delay of doing it in software, or PIC10F320 to use its CLC if you need minimal delay), then order them preprogrammed from MicrochipDirect for production.
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1448
  • Country: us
  • Very dangerous - may attack at any time
Re: Small package decade counter?
« Reply #3 on: March 30, 2019, 12:33:49 pm »
74HC4017 is available in a 2.5 x 3.5 mm DHVQFN package.
 

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Small package decade counter?
« Reply #4 on: March 30, 2019, 04:59:19 pm »
The GreenPak and and DHVQFN solutions are too small to solder by hand. I can't tolerate the propagation delay of a PIC. Looks like I will have to use a 74HC4017 in a TSSOP package. Thanks for the suggestions.
 

Offline DaJMasta

  • Super Contributor
  • ***
  • Posts: 2356
  • Country: us
    • medpants.com
Re: Small package decade counter?
« Reply #5 on: March 30, 2019, 05:23:52 pm »
+1 to using a micro for very small size, you could easily get a SOIC-8 or even a SOT-323-6 and have it act as a 10x divider.  They're not as popular as the binary counters, so they're less likely to come in a lot of varieties, though if you scour the net you can likely find something in TSSOP size, at least.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13119
Re: Small package decade counter?
« Reply #6 on: March 30, 2019, 06:16:00 pm »
If you use the PIC10F320 I mentioned's CLC module, you can get the propagation delay down to tens of nanoseconds.   

Method: 
Set up the CLC as a D type flipflop, clocked by your input signal on RA2 (T0CKI/CLC1IN1), a software selectable fixed 0 or 1 level to D, and Q output to RA1 (CLC1 out).  Set up Timer 0 for external clock (T0CKI) and preload it with 251 so it will rollover on the fifth input pulse.  Do NOT enable interrupts.

The main program consists of an endless loop that waits for TMR0IF to get set, then clears it, reloads Timer 0 with 251, and toggles the CLC flipflop D input by XORing a 1 into the appropriate bit of CLC0POL.   That should only take 10 instruction cycles worst case, so it should be possible to divide input signals of up to 2MHz.  The output will be a 1/10 frequency squarewave with very little propagation delay from the active edge of the input signal.
 

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Small package decade counter?
« Reply #7 on: March 30, 2019, 07:37:46 pm »
Thanks Ian. I don't have a PIC10F320 but I am going to place a Mouser order on Monday. I will order a couple and give it a try.

I have a question about how to use a 74HC40103 but will start another thread for that.
 

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Small package decade counter?
« Reply #8 on: March 30, 2019, 08:09:24 pm »
Ian, I also need to divide a 400 Hz signal by 200. It appears the PIC10F320 could handle that without breaking a sweat. If it only takes about 10 instruction cycles, I would have a safety zone of about 45 instructions. Does that sound right to you?

I will post the 74HC40103 question anyway since I am curious about how it works.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13119
Re: Small package decade counter?
« Reply #9 on: March 30, 2019, 08:39:50 pm »
I said, the loop can be done in 10 instruction cycles:

Code: [Select]
   radix dec ;default to decimal numbers


   movlw -5 ; Prepare W with Timer 'bump' value
Loop:
   btfss INTCON, TMR0IF ;Wait for Timer 0 rollover
   goto Loop ;(2 Tcy)

   addwf TMR0,F ;'Bump' timer to 5 counts before rollover
   bcf   INTCON, TMR0IF ;Clear rollover flag

   movlw 1<<LC1G2POL ;toggle flipflop D input                               
   xorwf CLC1POL

   movlw -5 ; reload W with Timer 'bump' value
   goto Loop ;(2 Tcy)
However if it just misses the rollover I think it will actually take 12 cycles all-in, so at 16MHz Fosc, you cant have less than 3us between output edges.   

I was also wrong about the max input frequency - Timer 0 increment is inhibited for 2 Tcy after its written, which in the code above happens between 3 and 6 Tcy after rollover so there cant be less than 8 Tcy between active input edges or it risks missing one.  That limits the max input frequency to 500KHz.


However as your signals are more than three orders of magnitude slower, you shouldn't run into any speed issues - you can even afford to drop the PIC clock speed to reduce power consumption.
The same code will do for any even division ratio between 2 and 510, just change the constant in the 'Bump timer' MOVLW.


N.B. Don't forget to clear ANSELA in the initialisation to make all pins digital, or it wont 'see' the input signal!
« Last Edit: March 30, 2019, 09:02:15 pm by Ian.M »
 

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Small package decade counter?
« Reply #10 on: March 30, 2019, 08:55:21 pm »
Thanks Ian. I will test it late next week.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13119
Re: Small package decade counter?
« Reply #11 on: March 30, 2019, 09:19:16 pm »
For division ratios that are a multiple of four and are 16 or greater its even simpler - configure the PIC10F320 to use your signal as its system clock input and it will execute one instruction every four clock cycles so its just a matter of writing a program to toggle a pin with a delay in the loop to get the right division ratio:

Code: [Select]
Loop:
   bsf LATA,0 ;Pulse RA0 on
   bcf  LATA,0 ;for four cycles
   ; delay goes here
   goto Loop ;(2 Tcy)


Or for the squarewave version, which has a minimum division ratio of 24:
Code: [Select]
Loop:
   bsf LATA,0 ;Pulse RA0 on
  ; delay goes here
   nop ; to match GOTO execution time
   nop
   bcf  LATA,0 ; and back off
   ; same delay goes here
   goto Loop ;(2 Tcy)

Edit: although its standard midrange core it has a LATA SFR so code fixed to use it!
« Last Edit: March 31, 2019, 07:26:54 pm by Ian.M »
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6257
  • Country: de
Re: Small package decade counter?
« Reply #12 on: March 31, 2019, 06:42:25 pm »
Just use one of the cheap SO-8 divide-by-10 prescalers. Who cares if it's specified for 200 MHz, it will work anyway.
 

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Small package decade counter?
« Reply #13 on: April 01, 2019, 03:15:06 am »
Ian, is it possible for RA2 to feed both TMR0 and the CLC module?
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13119
Re: Small package decade counter?
« Reply #14 on: April 01, 2019, 05:30:48 am »
I wouldn't expect any issues with RA2 feeding both TMR0 and the CLC module, and still being readable as an input pin.  FIGURE 10-1: I/O PORT OPERATION in the datasheet indicates the feed to all the peripheral inputs is a straight tap-off from the input of the  PORTA read buffers, after the ANSELA gating.  Also there's nothing in the TIMER 0 or CLC sections to indicate that their inputs require exclusive use of the input pin.  Worst case: if I'm wrong, link RA2 and RA0 and feed the input to both of them then the CLC can use CL1IN0 on RA0 instead of CLC1IN1 on RA2..

Perhaps you are thinking of the PIC10F2xx families, which have a Timer 0 module tha takes exclusive use of GP2?
 

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Small package decade counter?
« Reply #15 on: April 01, 2019, 06:47:01 am »
Thanks Ian. Like you, I didn't see anything that indicated you couldn't drive both TMR0 and the CLC module. But Microchip's documentation is notoriously bad about leaving out critical information. Or inserting incorrect information.

The only way to confirm what works is to give it a try.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3525
  • Country: it
Re: Small package decade counter?
« Reply #16 on: April 01, 2019, 07:31:15 am »
FWIW it's not THAT hard to solder a QFN with 0.5mm pitch.. i find it much harder to do a 0.5mm TQFP. You just need a fine tip on the iron

Quote
But Microchip's documentation is notoriously bad about leaving out critical information.
It's not. You haven't read many datasheets if you think that.
Quote
Or inserting incorrect information.
See above.

Another idea: Could you use the NCO module? Once you set the accumulator increment you're good to go, no need to reload
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 13119
Re: Small package decade counter?
« Reply #17 on: April 01, 2019, 08:48:05 am »
Nope.  I considered the NCO, but its got a 20 bit accumulator and only a 16 bit increment register so there's four overflow bits you cant directly increment, therefore  its max output frequency in pulse mode is fractionally under 1/16 of the input frequency, and for an exact integer division ratio the best it can do is 1/32.    It also doesn't work out to an exact ratio if you try to divide by 200.

Its also a great pity Timer 2 doesn't have an external clock inut and Timer 0 doesn't have a period register
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3525
  • Country: it
Re: Small package decade counter?
« Reply #18 on: April 01, 2019, 09:38:03 am »
Ah pity. True that, but the 10F322 is baseline for a reason >:D

What about the ATTINY 10 then? i see that these are the new parts in SOT-323 package, apparently it has a timer with period match/output compare and external clock input
 

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Small package decade counter?
« Reply #19 on: April 02, 2019, 12:19:36 am »
Quote
It's not. You haven't read many datasheets if you think that
Maybe notoriously was a little heavy handed. However, over the last couple of years the copy/paste errors seem to have increased.

https://www.microchip.com/forums/m1064174.aspx?high=datasheet+errors

https://www.microchip.com/forums/m1075692.aspx

https://www.microchip.com/forums/m1071093.aspx

https://www.microchip.com/forums/m896832.aspx?high=datasheet+errors

https://www.microchip.com/forums/m1012037.aspx?high=datasheet+errors

Maybe they are trying to do too much with too little resources.

About 6 months ago I designed a board using the PIC16F1719. Section 13.0 says
Quote
All pins on all ports can be configured to operate as Interrupt-on-Change (IOC) pins.
I made the mistake of interpreting that to mean ALL port pins have IOC capability. I did not read the entire section about each individual PORTx operation. I designed the board and ordered prototypes. When I started writing the program for the board that is when I discovered that none of the PORTD pins have IOC. As luck would have it, I had used one of the PORTD pins as part of the IOC operation. Luckily I was able to work around it by just checking the switch each time through the main loop. I realize it was my mistake by not reading the additional 27 pages about each of the I/O ports. Now I do. It is just another example of a copy/paste error.
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 855
Re: Small package decade counter?
« Reply #20 on: April 02, 2019, 02:43:29 am »
If sticking to powers of 2, you can use fixed duty cycle of nco. Since we are talking relatively low speeds (100Hz,400Hz), there is plenty of time to load a few registers.

NCO INC = 1
use NCO CLK pin

div10 = 256 - 10/2
div200 = 256- 200/2

loop:
    ACCL = div10
    ACCU = 255
    ACCH = 255
    wait while NCO1IF == 0
    NCO1IF = 0


 

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Small package decade counter?
« Reply #21 on: April 04, 2019, 07:08:28 pm »
Ian, I have programmed a PIC10F322 but am not getting any division of the input signal. The output on pin RA1 (CLC1) is the same as the input on RA2 (T0CLKI). I also tried to assign CLC1IN2 to RA2 which would mean T0CKI and the Flip-Flop had the same inputs. That also gives me 200 Hz out of RA1.
Code: [Select]
#include "p10f322.inc"
   
; CONFIG
 __CONFIG _FOSC_INTOSC & _BOREN_OFF & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _LVP_OFF & _LPBOR_OFF & _BORV_LO & _WRT_OFF

RES_VECT  CODE    0x0000    ; processor reset vector
    GOTO    START   ; go to beginning of program

MAIN_PROG CODE ; let linker place main program
    radix dec ;default to decimal numbers
 
START
    CLRF    TRISA   ; all pins are outputs
    CLRF    LATA    ; clear all latches
    CLRF    ANSELA  ; all pins digital
    bsf     TRISA, 0 ; RA0 is an input
    bsf     TRISA, 2    ; RA2 is an input
    CLRW
   
    ; setup CLC module, input on RA2, Flip-Flop output on RA1
    movlw   0x01
    movwf   CLC1SEL1 ; CLCIN1 assigned to LC1D3S, RA0
    movlw   0xC4
    movwf   CLC1CON ; D Flip-Flop, port pin output enabled, module enabled
    movlw   0xAA
    movwf    CLC1GLS0 ; gating OR, no inversion
   
    ; setup TMR0
    movlw   0xE8  ; External clock on RA2, rising edge, no prescale
    movwf    OPTION_REG
    movlw -5 ; Prepare W with Timer 'bump' value
   
Loop:
    btfss INTCON, TMR0IF ;Wait for Timer 0 rollover
    goto Loop ;(2 Tcy)

    addwf TMR0,F ;'Bump' timer to 5 counts before rollover
    bcf   INTCON, TMR0IF ;Clear rollover flag

    movlw 1<<LC1G2POL ;toggle flipflop D input                               
    xorwf CLC1POL

    movlw -5 ; reload W with Timer 'bump' value
    goto Loop ;(2 Tcy)
   
    END
Do you see any problem with the code setup? I don't completely understand the CLC module but I think I have is setup correctly.

Edit: Corrected a couple of errors in the CLC code setup area.
« Last Edit: April 05, 2019, 06:23:25 am by rcbuck »
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 855
Re: Small package decade counter?
« Reply #22 on: April 04, 2019, 08:29:43 pm »
Here is an nco version, can try if you want. I don't know if it will work. The nco io looks like its supposed to be async, so just have to worry about reloading acc values before the next rising edge which should not be a problem with the speeds you are talking about.
Code: [Select]
#include <xc.h>
#define DIV 10 //div ncoclk in by (power of 2)
#define RELOADval 256-(DIV/2) //if DIV was not power of 2, it is now
void main(void) {
    ANSELAbits.ANSA1 = 0; //RA1, NCO1CLK <-
    TRISAbits.TRISA2 = 0; //RA2, NCO1 ->
    NCO1INCL = 1; //inc by 1
    NCO1CONbits.N1OE = 1; //NCO1 ->
    NCO1CONbits.N1EN = 1; //NCO1 on
    for(;;){
        NCO1ACCH = NCO1ACCU = 255;
        NCO1ACCL = RELOADval;
        while( PIR1bits.NCO1IF == 0 );
        PIR1bits.NCO1IF = 0;
    }
}
NCO1CLKbits.N1CKS may need to be setup, the default reset value shows as using the NCO1CLK pin (0b00), but the nco diagram shows NCO1CLK as 0b11.

I don't know if this would also work if needing any div value (not just powers of 2)-
Code: [Select]
#include <xc.h>
#define DIV 10
#define RELOADval 256-DIV

void main(void) {
    //RA0 = CLC1IN0 (clock in)
    ANSELAbits.ANSA0 = 0; //digital
    CLC1CONbits.LC1MODE = 2; //4input AND
    CLC1SEL0bits.LC1D1S = 1; //same source for all - CLC1IN[1]
    CLC1SEL0bits.LC1D2S = 1; //pinouts use CLC1IN0,CLC1IN1
    CLC1SEL1bits.LC1D3S = 1; //clc datasheet chapter uses CLC1IN1,CLCIN2
    CLC1SEL1bits.LC1D4S = 1; //so assume CLC1IN0 = CLC1IN1, CLC1IN1 = CLC1IN2
    CLC1GLS0 = 0x55; //AND all 4 to gate
    CLC1GLS1 = 0x55;
    CLC1GLS2 = 0x55;
    CLC1GLS3 = 0x55;
    CLC1POL = 15; //(invert for AND)

    //RA2 NCO1 output (divided clock out)
    TRISAbits.TRISA2 = 0;
    NCO1INCL = 1;
    NCO1CONbits.N1OE = 1;
    NCO1CLKbits.N1CKS = 0b11; //LC1OUT (diagram shows 0b10)

    NCO1CONbits.N1EN = 1; //enable nco
    CLC1CONbits.LC1EN = 1; //enable clc

    for(;;){
        PIR1bits.NCO1IF = 0;
        NCO1ACCH = NCO1ACCU = 255;
        NCO1ACCL = RELOADval;
        while( PIR1bits.NCO1IF == 0 ){       
            while( CLC1CONbits.LC1OUT == 0 ); //wait for clock edge
            CLC1POL ^= 0x80; //flip polarity
        }
    }
}
The clc is just used to get a 'pulse' to the nco clock via lc1out, manually changing polarity on each edge of the input clock. The nco still does divide by 2 as it toggles its output on each rising edge, but now any value can be used since we provide a rising edge on each clock transition. The LC1OUT is clocked on Q1, so you are then somewhat tied to fosc a little and lose total async (if important). CLC1 output and NCO1CLK input are on the same pin, but I don't think you could get both to work (could try, though)- then you would be about as async as possible.

« Last Edit: April 05, 2019, 12:35:00 am by cv007 »
 

Offline rcbuckTopic starter

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Small package decade counter?
« Reply #23 on: April 05, 2019, 06:18:34 am »
cv007, I don't think the NCO can be used. I don't think it is accurate enough. I don't want to depend on the processor clock for any of the timing requirements.

From reading the Microchip documents I believe the PIC10F322 will work. The only thing that is confusing about the CLC module is the output. There is no selection for CLC1OUT. However, I think that CLC1 is actually the output.

I have a PIC12F1501 that has the CLC module in it. I will test that tomorrow to see if I can get it to work.

If I can't get the CLC module to work in the PICs I will just use a larger package discrete decade divider chip.
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 855
Re: Small package decade counter?
« Reply #24 on: April 05, 2019, 06:57:09 am »
Quote
I don't want to depend on the processor clock for any of the timing requirements
From what I read, the nco clock input, adder, output are all on their own where the adder works on the rising edge. The only processor involvement is the instructions to watch the nco flag, and load the accumulator. It seems there is no way to avoid having some instructions involved so you will always have that no matter what, but they do not affect your divided clock until you get to a speed where the instructions get in the way. With a 16MHz clock, I think a 400 khz clock input can be done (16M/4/10 instruction cycles, or whatever needed can be done before the next rising edge).

The version where the clc clocks the nco will introduce jitter on the incoming edges as the lc1out is clocked at Q1 (this version is only if odd div values needed). If the ncoclk input (ra1) works when the clc1 out (ra1) is also working (don't know), then the lc1out can be eliminated and the clc1 output directly drives the nco, and the resulting divided clock is again async to fosc.

Quote
I don't think the NCO can be used. I don't think it is accurate enough
I'm not sure what that means. The nco can count to 5 just fine(from -5 to 0 anyway)- the accumulator is pre-loaded, the increment value is 1, then the accumulator is incremented by 1 on every rising edge of ncoclk. When the accumulator overflows, the nco output toggles its output (all async from what I can tell). You now reload the accumulator, and do again.
« Last Edit: April 05, 2019, 07:13:50 am by cv007 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf