Hi guys,
i am using the Timer1.zip (http://www.arduino.cc/playground/Code/Timer1) to generate a PWM signal on PIN 9. Now my question is, how i can run a ISR or specific function when the PWM level is going from HIGH to LOW. It should trigger a second pulse on Pin 10 every x cycles on PIN 9 LOW. My first attempt to output something with the example below didn't work at all :-/ At least i was able to setup up any frequency and duty cycle required.
Bye
xcron
/*
* Timer1 library example
* June 2008 | jesse dot tane at gmail dot com
*/
#include "TimerOne.h"
int Tastgrad;
long dutycycle;
int Frequenz;
int freq;
int Tperiod;
void setup()
{
Frequenz = 300; // Frequenz in Hz
Tastgrad = 80; // Tastgrad in %
dutycycle = Tastgrad * 10.24;
freq = 500000 / Frequenz;
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
Timer1.initialize(freq);
Timer1.pwm(9, dutycycle);
Timer1.attachInterrupt(callback);
}
void callback()
{
delayMicroseconds(50);
digitalWrite(10,HIGH);
delayMicroseconds(50);
digitalWrite (10,LOW);
}
void loop()
{
// your program here...
}