2 indipendent PWM on a Arduino UNO+Eth shield

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 ordet 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
  • 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.
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);
}

iw4blg:

  • pin 3 seems to be used by the Eth shield as well as the pins 0,1,2,4,10,14,15

The Ethernet Shield use SPI (Pin 11, Pin 12, and Pin 13) along with Pin 10 for the Ethernet SPI Slave Select and Pin 4 for the SD Card SPI Slave Select. It shouldn't be using pin 3. It can optionally use Pin 2 for the W5100 "INT" signal but the Ethernet library doesn't support it. It shouldn't be using Pin 14 (A0) or 15 (A1).

The FreqCount library (FreqCount Library, for Measuring Frequencies in the 1 kHz to 5 MHz Range) says:
Arduino Uno: Frequency Input Pin: 5 Pins Unusable with analogWrite(): 3, 9, 10, 11

That explains why 3, 9, 10, and 11 won't work for PWM.

So that leaves you with PWM pins:
3: Disabled by FreqCount
5: Needed buy FreqCount for counter input
6: Available
9: Disabled by FreqCount
10: Disabled by FreqCount and used by Etherenet Shield
11: Disabled by FreqCount and used by Etherenet Shield

Looks like if you can find another way to do frequency measurements you could possibly use 3, 5, 6, and 9

Do you need to measure very high frequencies (MHz)?

Hello and thanks for having made clear to me a number of things.
For my project the Arduino should:

  • read the OL frequency of the receiver (about 36MHz, divided by 8 from an external prescaler)
  • run a PLL-like control of the frequency
  • drive the VCO with at least 10bits of resolution
  • record the signal level from the receiver output
  • send data over the ethernet line

For reading the OL frequency I tried the library we talked about and it's fine
The problem now is to have a D/A of about 10 bits in order to drive the VCO. The pwm are only 8 bits. I thought to use 2 indipendent PWM output to mix up into an external integrator with the two inputs scaled 256 times each others. This build a 16 bits D/A.

But now it seems I'm stuck..
What about other boards, like the Mega for instance? Would that allow me to do what I need?

Thanks, regards.

Pierluigi

The Mega has a lot more pins so that should help.

For D/A you might want to consider an external chip. You can fined them with SPI and I2C interfaces. SPI will need only one additional pin (for the Slave Select) and I2C uses the SCL and SDA pins (A4 and A5 on the UNO). An external D/A should give you a nice clean analog value.