This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

64 bit edge counter using N2HET - RM48

Other Parts Discussed in Thread: HALCOGEN, RM48L950

We would like to use the N2HET1 module on our RM48L950 to create/manage a 64-bit counter that is externally clocked by a 32KHz square wave output from our Maxim RTC chip.  We are already using the N2HET1 module to control some pwm outputs with standard HALCoGen configuration and function calls.  I have 3 questions:

1. Is it possible to build a 64 bit edge counter that is clocked by an external square wave using the N2HET1 module? Ideally the CPU (application) would be able to initialize this counter to some non-zero value, enable it, and then the application could read from it as desired.

2. If possible, could anyone point me to an example of a 64 bit edge counter using N2HET

3. It seems that a hand built HET IDE project would not play nice with the N2HET setup within HALCoGen.  Should we be concerned with this 64 bit edge counter interfering with HALCoGen's PWM functionality?

If 64 bit was a hang up, a 32 bit counter would work if we could interrupt the CPU upon counter roll over.

Thanks in advance for any help you can provide!

  • David,

    I would say that if you are using a 32KHz clock source as the input, you can simply use a sequence of instructions like this:

    ; Use these 2 lines to actually run the program w. pin input
    ; (rising edge on pin 1 is 32KHZ Input, but change as needed
    ; START BR { next=NO_EVT,cond_addr=EVT_DET,pin=1,event=RISE};
    ; EVT_DET ADD { src1=ONES,src2=IMM,dest=NONE,data=0,hr_data=1};

    ; Use these 2 lines to test the counter
    ; After a few counts, set L01 data field ahead to 0xFFFFFFFC
    ; and run a few more loops through the rollover...
    START BR { next=NO_EVT,cond_addr=EVT_DET,pin=1,event=NOCOND};
    EVT_DET ADD { src1=ONES,src2=IMM,dest=T,data=0,hr_data=1};

    L00 ADC { src1=IMM,src2=ZERO,dest=IMM,data=0,hr_data=0};
    L01 ADC { src1=ZERO,src2=IMM,dest=IMM,data=0,hr_data=0};
    NO_EVT BR { next=START,cond_addr=START,event=NOCOND };

    This of course assumes your loop resolution period is << 1/32KHz but I think that's reasonable as an assumption.

    If you can work with a 57 bit counter instead of a full 64-bit counter, then you might be able to use the ECNT instruction and save an instruction but I'd need to think this through more.  It's not so straightforward this way, since you need to increment the upper 32-bits when the ECNT field rolls over from 0xFFFFFF80 to 0x00000000.   

  • Thank you Anthony!

    I believe you answered our first two questions - thanks for the example HET code.

    Would you be able to comment on our 3rd question?  I have not dug into all the code HALCoGen generates for the N2HET module when the basic PWM functions are used.  Is HALCoGen likely to interfere with any hand written HET code?

  • Hi David,

    Sorry I missed the last question.   Yes, you definitely will not be able to simply use the HalCoGen built-in PWM code once you start adding your own instructions to the HET program.   The closest that you might come is to use the HalCoGen code on one HET and your own on another HET as long as you're using one of the RM48 or RM46 parts.  If you are on RM42 then there is only 1 HET and you don't have this luxury.

    That much said - I think the HET program that comes with HalCoGen is more for 'out of the box' productivity and it's a good investment once you've decided to use the Hercules product to learn to program HET.   The HET IDE includes code templates for PWMs that you can paste in and easily add PWMs to your own custom program.   Hopefully this can be a bridge between the 'out of box' HalCoGen code and a full custom HET program of your own.

    The HET IDE also gives you visibility into how the HET executes code in a way that's not possible with silicon.  And the capabilities of Synpaticad for generating test benches (if you upgrade to the full product) are pretty awesome.   Definitely worth the time to learn this tool if at all possible.