Okay so I have been troubleshooting and testing a lot. I think the problem was I did both measuring and outputting frequency on the same Arduino. I borrowed one extra and did frequencychanging on one, and measuring on the other.
This is the code i used and it worked:
#include <PWM.h>
int ut = 9;
int32_t frequency = 1500;
void setup() {
InitTimersSafe ();
SetPinFrequencySafe (ut, frequency);
}
void loop() {
pwmWrite (ut, 127); //går fra 0-255
}