Proper setup for Atmega1281 Timer/Counter1 of the Zigbit A2

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ref: Atmega1281 datasheet, page 136, 16-bit Counter/ Timer section
I am trying to setup the Atmega1281 Timer/Counter1 of the Zigbit A2 module to perform frequency measurements on the Input Signal that is 10 milliVolts p-p at 1 Hz to 40 KHz. The Input Capture Pin (ICP1) might not trigger on this low voltage source.
This setup is more difficult since Timer/Counter 1 is configured in BitCloud for PWM output mode.
The Analog Comparator(AC) has the input sensitivity required but is not supported in BitCloud.

Thus far, my setup would configure Timer1 in Input Capture mode:
1. Using the register TCCR1B configure the bit ICES1 =1, this triggers on the positive edge on the Input Capture Pin (ICP1) {Zigbit pin# ??}
2. Apply the Input Signal on the pin ICP1.
3. In the ISR of Input Capture interrupt, copy the ICR1 to an array variable.
4. If ICES1 is 1, then corresponding counter value TCNT1 is captured in the ICR1 register on the rising edge of the signal.
5. Similarly on the next rising edge, ICR1 is copied to next array element.
6. Now the difference of the adjacent array element will provide the time interval between to two consecutive rising edges.
7. Some coding has to be included to handle the timer overflow.

Then, Configuring the Analog Comparator:
AIN0 and AIN1 are the inputs to the Analog Comparator. These are PE_2 (pin 40) and PE_3 (pin 41) on Zigbit pinout, respectively.
1. ACSR Resister is used to configure the Analog Comparator.
2. If ACBG is set to 1, then the fixed bandgap reference voltage is internally connected to AIN0 pin. A delay is required for voltage stabilization, or else the first ACO will be a wrong).
3. ACIS1, ACIS0 bits select the triggering event for the Analog Comparator based on the ACO value.
4. If ACIS1= 1 and ACIS0=1, then interrupt is triggered if the Analog Comparator Output (ACO) value changes from 0 to 1.
5. Configure and test these ideas, separately. Change Input Capture interrupt trigger source to the Analog Comparator Output (ACO) by setting the
ACIC to 1. The ACIC bit decides whether ICP1 pin or AIN0 and AIN1 pins trigger the input capture. When ACIC is enabled, then it is the ACIS1,
ACIS0 bits that fire the trigger event and not the ICES1.

I am hoping for Suggestions/Comments on the correct approach for this setup.
Thanks in advance for your help.

Asking a better question, is the beginning of learning.
**********************
New Hardware Hackers SIG in San Diego, CA Meets 2nd. Tuesday, more info www.Spincraft.com
***********************

Last Edited: Fri. Oct 16, 2015 - 02:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may not use BitCloud's PWM if you don't need it.

Your approach will use a lot of CPU and likely to interfere with the networking stuff.

At 40 kHz you'll have 200 cycles (given that CPU runs at 8 MHz) to process one transition. It is possible if this measurement process is the only thing that is going on at the time, but not with other stuff running in the background.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for your insightful comments, Alex!

The frequency that is being measured was generated by the motor RPM sensor. So, it does not have to be sampled, continuously. Motor speed changes do not happen often (once in 5 seconds or more). The motor controller is a BitCloud Router and is reporting this motor RPM to the COOR. Reporting the RPM can happen by exception when it changes but not greater than 1x per second.

Of course, the motor controller has a PID loop to maintain the commanded RPM. So, another PWM is driving the motor H-Bridge. This PID loop could be updated 1x per second since the load does not change often. The A/D is monitoring the motor applied voltage & current for load variations, once per second loop.

I am using the Zigbit A2 module for development & testing. The 1281 will be busy. Can I estimate the limits of this MCU? Also, what about the ICP voltage levels? Is 10 milliVolts below their range?
Should I be looking for a faster MCU?
Best Regards

Asking a better question, is the beginning of learning.
**********************
New Hardware Hackers SIG in San Diego, CA Meets 2nd. Tuesday, more info www.Spincraft.com
***********************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

10 mV is definitely lower that ICP threshold. I would use external comparator or even external MCU (like AtTiny) to do the job. After external comparator a viable option might be a RC-filter and sampling resulting analog value.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your reply. I prefer to use the on-board AC to do this job. PCB space is very constrained for this design (max width = 10 mm). A QFN64 package is 9x9 mm and the max. IC that could fit.

Please let me know your thoughts on the 1281 MCU. Is it capable of handling this load with the loops described above?

Thanks

Asking a better question, is the beginning of learning.
**********************
New Hardware Hackers SIG in San Diego, CA Meets 2nd. Tuesday, more info www.Spincraft.com
***********************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Put at least external comparator to use ICP, they are small.

As for the described method - it might work, but I would not recommend doing this. Or at least make a prototype and see if it works or not.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, if the 1281 can't handle this, then would the ATxmega256A3 @ 32MHz be on the upgrade path with a RF231 transceiver and be BitCloud code compatible? I'm guessing the HAL needs to be modified.

Asking a better question, is the beginning of learning.
**********************
New Hardware Hackers SIG in San Diego, CA Meets 2nd. Tuesday, more info www.Spincraft.com
***********************

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not saying it can't, I'm saying you need to check. I will say exactly the same for Xmega, 4 times more time to do the job is nice, but who knows. All you need is 40 kHz frequency generator and some time, this will save you time in the future.

There is support for 32MHz in the HAL already.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your insights.
best regards

Asking a better question, is the beginning of learning.
**********************
New Hardware Hackers SIG in San Diego, CA Meets 2nd. Tuesday, more info www.Spincraft.com
***********************