Author Topic: AVR - ATmega Zero Cross Det.  (Read 13704 times)

0 Members and 2 Guests are viewing this topic.

Offline delwinbestTopic starter

  • Newbie
  • Posts: 5
AVR - ATmega Zero Cross Det.
« on: February 02, 2011, 07:44:00 pm »
Howdy all,

Know its been done before and there are hundreds of examples out there... but I'm got an awesome twist I'm trying to work with here.

It includes:
8 Analog Inputs
ATmega16
Rigol scope (ps don't give up guys working in the dis-assembly of the Rigol 1052 firmware in another thread)
Current Transformers
Some C programming :)

So I'm making use of the on chip multiplexer with is switching the Analogue to Digital Converter (ADC) as WELL as the Comparator.
My system is governed by interrupts, every second or so it changes the MUX to the next input, it then disables the ADC and enables the comparator and waits for a zero crossing, this multiplexing is not a problem and its all working, as far as I know.

The strange thing I\m running into is this, I'm not using the comparators interrupt, instead, I've configured it to Capture the contents of Timer1 (for frequency measurement), so the comparators interupts area and the Timer1 Input Capture Interrupt is enabled. This works fine, however, I'm now unable to select the rising or falling edge as a trigger, it only interrupts on the falling edge.  :(

And in theory this should not be so... or do I have this wrong????

Anyone ever worked on something similar?  ???

Ultimately I want to measure the frequency and amplitude or all inputs.  :)
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10222
  • Country: nz
Re: AVR - ATmega Zero Cross Det.
« Reply #1 on: February 02, 2011, 11:42:42 pm »
There are three things i noticed in the datasheet that may be something to do with your issue....



There is this bit in the datasheet about the comparators rise/falling edge triggering

"When changing the ACIS1/ACIS0 bits, the Analog Comparator Interrupt must be disabled by
clearing its Interrupt Enable bit in the ACSR Register. Otherwise an interrupt can occur when the
bits are changed."




The timer also says this

"Timer/Counter1 can alternatively use the Analog Comparator output as trigger source for the
Input Capture unit. The Analog Comparator is selected as trigger source by setting the Analog
Comparator Input Capture (ACIC) bit in the Analog Comparator Control and Status Register
(ACSR). Be aware that changing trigger source can trigger a capture. The Input Capture Flag
must therefore be cleared after the change
."





Also, i noticed this text on the ACIC bit for the comparator

"The comparator output is in this case directly connected to the
Input Capture front-end logic, making the comparator utilize the noise canceler and edge select
features of the Timer
/Counter1 Input Capture interrupt."


maybe you need to change the edge select mode for the timer and not the comparator ?
« Last Edit: February 03, 2011, 12:20:02 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline delwinbestTopic starter

  • Newbie
  • Posts: 5
Re: AVR - ATmega Zero Cross Det.
« Reply #2 on: February 03, 2011, 11:46:35 am »
There are three things i noticed in the datasheet that may be something to do with your issue....



Also, i noticed this text on the ACIC bit for the comparator

"The comparator output is in this case directly connected to the
Input Capture front-end logic, making the comparator utilize the noise canceler and edge select
features of the Timer
/Counter1 Input Capture interrupt."


maybe you need to change the edge select mode for the timer and not the comparator ?

Fantastic! Can't believe I missed this!

Bit 6 – ICES1: Input Capture Edge Select

No to continue with peak measurement.
Thanks a mil.
 :) :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf