Convert Digital input to PWM

Hi everyone,

If I have some 16-bit digital number come into Arduino, is there any way to convert those 16-bit numbers inside Arduino and generate as a PWM output?
I appreciate any help.

Yes, but the PWM does not have a 16 bit resolution. Only 8 bit.

If I understand you correctly the answer is yes if the "16 bit digital number" encodes the frequency and duty cycle of the desired pwm output.

What sends this number to the Arduino, and how does the Arduino read the number? How frequently does a new number come into the Arduino?

cattledog:
If I understand you correctly the answer is yes if the "16 bit digital number" encodes the frequency and duty cycle of the desired pwm output.

Unless you are content with some fixed frequency.

A MAX6675 thermocouple sent the data to Arduino(datasheet said it is a 16-bit number). And I am using this code to get the value. Instead to read celsius and Frehait number I would like to read the raw data and transfer them to PWM.

#include "max6675.h"

int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int vccPin = 3;
int gndPin = 2;

void setup() {
Serial.begin(9600);
// use Arduino pins
pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);

Serial.println("MAX6675 test");
// wait for MAX chip to stabilize
delay(500);
}

void loop() {
// basic readout test, just print the current temp

Serial.print("C = ");
Serial.println(thermocouple.readCelsius());
Serial.print("F = ");
Serial.println(thermocouple.readFahrenheit());

delay(1000);

What raw data?

aarg:
What raw data?

The data that Arduino saw before converted to Celsis and Frehait number

DDaw:
The data that Arduino saw before converted to Celsis and Frehait number

Does the MAX6675 library have a method to return that? Why do you need it?

The data that Arduino saw before converted to Celsis and Frehait number

The data sent from the sensor is a 12 bit number (0-4096) of .25C values. If you multiply the readCelcius() number by 4 you will have the “raw” data.

What do you want to do with it?

aarg:
Does the MAX6675 library have a method to return that? Why do you need it?

I don't think the library has. Actually, I just guess I will need the raw data. Anyway, my goal is to convert whatever the thermocouple read to a PWM. Is there any better method?

Better method to do what? Why do you need this? What is wrong with a C/F reading? The sensor just returns the Celsius temp times 4. So if you multiply the C reading by 4, you will have the raw data.

double MAX6675::readCelsius(void) {

  uint16_t v;

  digitalWrite(cs, LOW);
  _delay_ms(1);

  v = spiread();
  v <<= 8;
  v |= spiread();

  digitalWrite(cs, HIGH);

  if (v & 0x4) {
    // uh oh, no thermocouple attached!
    return NAN; 
    //return -100;
  }

  v >>= 3;

  return v*0.25;
}

aarg:
Better method to do what? Why do you need this? What is wrong with a C/F reading? The sensor just returns the Celsius temp times 4. So if you multiply the C reading by 4, you will have the raw data.

Since transmitters can not read C/F values, I will need Arduino to generate PWM for a transmitter based on the C/F value.

aarg:
Yes, but the PWM does not have a 16 bit resolution. Only 8 bit.

You can do 16-bit PWM if you access timer 1 (e.g.) directly.

cattledog:
The data sent from the sensor is a 12 bit number (0-4096) of .25C values. If you multiply the readCelcius() number by 4 you will have the "raw" data.

What do you want to do with it?

I see. Then I think that I need to write those numbers back to Arduino's register and generate the PWM. Any code can do this?

Blackfin:
You can do 16-bit PWM if you access timer 1 (e.g.) directly.

May I see any examples? how to generate the PWM

DDaw:
May I see any examples? how to generate the PWM

Which Arduino are you using?

16 bit PWM will be at a lower PWM master frequency. Again, what are you planning to do with the PWM output?

Blackfin:
Which Arduino are you using?

Arduino Mega 2560

aarg:
16 bit PWM will be at a lower PWM master frequency. Again, what are you planning to do with the PWM output?

PWM is going into a transmitter, so I can receive the data far from my Arduino board

DDaw:
Arduino Mega 2560

And what frequency do you need?