# Generating two different frecuencies signal

Hi everyone . I’ve been trying to generate two different signals (sine and triangle) in Arduino Mega. I need a high frecuency triangle signal and that’s why I included TimerThree.h library. The fact is when I run both fuctions one of them changes its frecuency. Any idea about how to run my program without changing the signal frecuencies? . I leave the code below.
#include <TimerThree.h>

``````const int Pin = 5;
int PIN=13;
int seno[ ] = {130,176,215,241,250,241,215,176,130,84,45,19,10,19,45,84,130};
void setup()
{
pinMode(PIN,OUTPUT);
Timer3.initialize(40);  // 40 us = 25 kHz
Timer3.attachInterrupt(control);
}
void control()
{
for (float x =0.0; x < 255.0; x++) {
Timer3.pwm(Pin, (x/255) * 1023);
}
for (float x = 255.0; x > 0.0; x--) {
Timer3.pwm(Pin, (x / 255) * 1023);
}
}
void loop() {
for(int i = 0; i<17 ;i++){
if(seno[i]>255) {
seno[i]=255;
}
analogWrite(PIN, seno[i]);
}
}
``````
``````int seno[ ] = {130,176,215,241,250,241,215,176,130,84,45,19,10,19,45,84,130};
``````

Why do you need an int array to hold byte values?

While your interrupt service routine is running, other interrupts, needed by analogWrite() for instance, can't be triggered.

You're going to need to find a completely different way of generating the triangle wave.

You do realize, I hope, that the most optimistic outcome of this approach will be a frequency that is 1/17 of the PWM frequency?

Please edit your post so that`#include <TimerThree.h>` is part of your code where it belongs. Please also provide a link to the library in question.