Frequency Counter Library

Hello to everybody, first of all I'm not an expert altought I have succeed so far with some small Arduino based project.
I'm now trying to develop a radioastronomic receiver (radiometer) controlled by Arduino.
Now the topic:

  • I have an Arduino Uno rev.2 with an Ethernet shield with microSD slot (both not yet used, but useful later on)
  • In order to control the receiver I have to program 2 different PWM on 2 different pins
  • for what I read on the web pages, I can use the instruction analog.write(pin,pwm) on the pins 3,5,6,9,10,11 if not already used by other devices
  • the pin 5 (T1) is used to read the OL frequency of the receiver by means of the library FreqCounter.h herewith discussed..
  • pin 3 seems to be used by the Eth shield as well as the pins 0,1,2,4,10,14,15
  • thus, "fre to be used" for my purpose, remain the pins 6,9,11

Unfortunately only the output on the pin 6 works. Pins 9 and 11 always are at low level, no PWM, even with no shield on top of the Arduino Uno.
The board works fine is I do not call the frequency reading routine.
What I'm doing wrong? Waht shall I do to fix the trouble?
On the following a draft of the cose I'm using. Please note it's a very early draft of what I would do, so several variables are defined but not used yet.

Many thanks to all for the help!
Pierluigi

#include <FreqCounter.h>

// OL input on digital pin #5

const short pwm1=9; // pin 9 is 8 MSB PWM
const short pwm2=6; // pin 6 is 8 LSB PWM

long int frq; //frequency read
long int IF=10700000; // first IF of the Rx
const short prescaler=8; // scale factor of the ext. prescaler
const long int fastro1=25610000; // astro1 = 1st frequency
const long int fastro2=13385000; // astro2 = 2nd frequency
long int OLnow; // current OL frequency
long int RXnow; // current RX frequency
long int errore=0; // frequency error

int pwmh; // 8 MSB of PWM
int pwml; // 8 LSB of PWM

float Vastro1=0.2035; // VCO nominal input for fastro1
// float Vastro2=3; // VCO nominale per rx frequenza fastro2

int bitbase1=Vastro165535/5; // total PWM bits (res.16) of feed forward VCO a freq. astro1
// int bitbase2=Vastro2
65535/5; // bit di PWM totali (risoluzione 16) del feed forward tensione VCO a freq. astro1

void setup() {
Serial.begin(9600); // connect to the serial port
Serial.println("Frequency Counter");
}

void loop() {

FreqCounter::f_comp= 5; // Set compensation
FreqCounter::start(1000); // Start counting with gatetime of 100ms
while (FreqCounter::f_ready == 0) // wait until counter ready

frq=FreqCounter::f_freq; // read result
OLnow= frq*prescaler; // OL frequency calculation
RXnow= OLnow-IF; // RX frequency from IF and OL
errore= RXnow-fastro1; // tuning freq. errorcalcolo errore di sintonia

pwmh= bitbase1/256;
pwml= bitbase1-256*pwmh;

analogWrite(pwm1, pwmh);
analogWrite(pwm2, pwml);

Serial.print("bitbase1= ");
Serial.print(bitbase1);
Serial.print(" pwmh= ");
Serial.print(pwmh);
Serial.print(" pwml ");
Serial.print(pwml);
Serial.print(" frq= ");
Serial.print(frq);
Serial.print(" OLnow= ");
Serial.print(OLnow);
Serial.print(" RXnow= ");
Serial.print(RXnow);
Serial.print(" Errore= ");
Serial.println(errore);
delay(20);
}