Dear friends, it´s me again. Well ... I have made some research on this and this is my first attempt. I works fine but unfortunately I yet couldn´t find the way to leave the main timer running al the time.
Here is the code ... it is just an osciloscope test. I used the MTIM to simulate the 50 Hz mains zero crossing input. This interrupt should be changed to be Input Capture on channel 0 in real life, signal that is taken from the zero crossing detector. Somebody may find the "timer.h" module useful. This is my two pennies. My test runs in a DEMO9S08QG8 board. PTB6 outputs a "line sync" signal and PTB7 is output for the TRIAC.
I will keep on reading and researching, but here is my comment at this point. With all my respect, my conclusion is that this timer has a very important functional consideration regarding the main counter overflow synchronism dependency. There is an extremely important paragraph taken from the MC68HC908AP64 Rev. 3 8/2005 manual @ page 138 9.4.3.1 " Unbuffered Output Compare" , that is also repeated in many other manuals. It was obviously removed from the new chip versions. The text is confusing, but one can understand what it means using a bit of imagination and navigating among the poor, not revised semantics. This explains why this timer - in the way it has been designed - cannot take full advantage of a wide range of applications and other many possibilities. It has been thought just for PWM use. IMHO I would have added a couple of bits in some register to allow some "extras" to sometimes disengage the logic from the overflow event at the moment of reloading the new compare value. Allow me to copy (literally) this small paragraph here, that can be perfectly applied to the QG8 with some imagination and can help somebody else:
"Any output compare channel can generate unbuffered output compare pulses as described in 9.4.3 Output Compare. The pulses are unbuffered because changing the output compare value requires writting the new value over the old value currently in the TIM channel registers. An unsichronized write to the TIM channel registers to change an output compare value could cause incorrect operation of up to two counter overflow periods. For example, writing a new value before the counter reaches the old value but after the counter reaches the new value prevents any compare during that counter overflow period. Also, using a TIM overflow interrupt routine to write a new, smaller output compare value may cause the compare to be missed. The TIM may pass the new value before it is written.
Use the following methods to synchronize unbuffered changes in the output compare value on channel x:
* When changing to a smaller value, enable channel x output compare interrupts and write the new value in the output compare interrupt routine. The output compare occurs at the end of the current output compare pulse. The interrupt routine has until the end of the counter overflow period to write the new value.
* When changing to a larger output compare value, enable TIM overflow interrupts and write the new value in the TIM overflow interrupt routine. The TIM overflow interrupt occurs at the end of the current overflow period. Writing a larger value in an output compare interrupt routine ( at the end of the current pulse ) could cause two output compares to occur in the same counter overflow period."
I don´t mean that correct behaviour cannot be achieved, it is just that it takes a certain amount software overload to analize these exceptions. Some of my questions here are:
1. considering this explanation, what means unsynchronized ? ( I think it is related to the overflow event )
2. what is smaller value /larger value , are these absolute values or they consider the overflow modulo ?
My next step is using the overflow interrupt ( absent in my code example ) to monitor these exceptions and splitting the desired results scenario in 3 phases that must be considered to reload the compare register and avoid stopping the timer.
I apologize for having used so much space and time, and please correct me if I am wrong in any of my thoughts.
Kind regards
Roberto Berner
Triac_test1.zipMessage Edited by t.dowe on 2009-10-27 12:17 PM