![]() (code for the latest release - r11) Oct 2012. I.e Google Code Archive - Long-term storage for Google Code Project Hosting. The code on GoogleCode doesn't seem to look the same as you posted. It seems to be that the Timer1 library doesn't really work that well for this sort of thing, and I may as well write the code myself. However this a hack, and I'd rather to it correctly. ![]() So the optimal way to do this is to pre initialise the Timer and get it to wait, (stop) and then start it in the zero crossing ISR.Īnd in the Timer ISR, the timer needs to be stopped, as it needed to be start again from time zero in the zero crossing ISR, otherwise the timer will not be synchronised with the zero crossing's which is the whole point of the exercise.Ĭurrently my work around, using Timer1, is to call stop() and then to set the timer counter to zero, but this causes a faux interrupt to the timer ISR, so I have to have a volative global which I set in the code that sets the counter to zero, so that I know that the interrupt is likely to be a faux one. The reason I need to init the timer before its used and then stop it, is because if I init the timer in the zero crossing ISR it takes quite a lot of time (at least if I used Timer1's init code), and this effects when the Timer ISR gets triggered. Each timer has two associated output pins: 6 and 5 for timer0, 9 and 10 for timer1, 11 and 3 for timer2. (Note this output is set to LOW in the zero crossing ISR). Timer1 is a 16-bit timer, so it can count up to 65535. In the timer ISR, the output that drives the triac( via an opto + signal conditioning), is set to HIGH. The time period is basically between zero and 10mS. In the zero crossing ISR, the timer needs to be started, as the triac that controls the AC load need to be triggered at a pre-defined time period after the zero crossing. The zero crossing detector is connected to D2 and hence uses Interrupt 0 to call an ISR Thats why many Arduino libraries have classes that implement an begin () method: for delaying the hardware initialization until after init () is done. And init () will reconfigure Timer 1 for PWM at 490 Hz. The Arduino get a zero crossing pulse every 10ms from a opto isolator connected to the mains via a signal conditioning circuit. Your constructor will be called before main (), and main () will call init () for initializing the Arduino core library. The whole project is a remote control ac mains dimmer controller based on various designs on the web. I've tested on a Uno and Nano with the same results Am I using the Timer1 library incorrectly.īTW. My current work around is to set a flag just before setting TCNT1 =0, and in the ISR, if the flag is set, I treat this as a false interrupt caused by the resetting of TCNT1 isResttingTimer=true ĭoes anyone know the correct / best way to do this. Timer1.resume() instead of start(), but as document in the Timer1 source code, setting TCNT1 =0 causes the interrupt handler to get called, on the next tick. The only solution I have found is just to set TCNT1 = 0 and then later call If you replace the stop() command with resume() it works fine, but the timer isn't reset to zero.Īnd I need to keep stopping the timer and starting it again. However in my simple example above, the timerisr doesn't get called. I don't want to call initialize just before I need the timer to start, as I need the timer to start straight away and initialize() runs quite a lot of setup code. I.e I need to be able to init the timer and then start it some time later. ![]() ![]() TODO: Put your regular (non-ISR) logic here Timer1.attachInterrupt( timerIsr ) // attach the service routine here Timer1.initialize(1000000) // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |