89 uint16_t
get_voltage(
float fullScaleVoltage, int8_t pwmBitResolution);
110 Serial.begin(115200);
113 char python_char =
'x';
114 for (
int i = 0;
i <= 50;
i++)
116 if (Serial.available() > 0)
117 python_char = Serial.read();
118 if ((python_char ==
'Z') || (python_char ==
'z') )
139 static int8_t selected_dac = 0;
141 if (Serial.available())
144 Serial.println(user_command);
146 switch (user_command)
158 Serial.println(
"Incorrect Option");
161 Serial.println(
"\n*****************************************");
173 Serial.println(F(
"*****************************************************************"));
174 Serial.println(F(
"* DCxxxxx Demonstration Program *"));
175 Serial.println(F(
"* *"));
176 Serial.println(F(
"* This program demonstrates how to implement a PWM signal *"));
177 Serial.println(F(
"* to set the LTC2645 DACs. "));
178 Serial.println(F(
"* *"));
179 Serial.println(F(
"* Set the baud rate to 115200 and select the newline terminator.*"));
180 Serial.println(F(
"* *"));
181 Serial.println(F(
"*****************************************************************"));
188 Serial.println(F(
"\nCommand Summary:"));
189 Serial.println(F(
" 1-Select DAC"));
190 Serial.println(F(
" 2-Set Duty Cycle"));
192 Serial.print(F(
" Selected DAC: "));
193 Serial.println((
char) (selected_dac + 0x41));
194 Serial.print(F(
" Current Duty Cycle: "));
196 Serial.println(F(
"%"));
197 Serial.print(F(
"Enter a command:"));
204 pinMode(
DAC_A, OUTPUT);
205 pinMode(
DAC_B, OUTPUT);
211 TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);
212 TCCR1B = _BV(WGM13) | _BV(CS10);
246 Serial.print(F(
"Select DAC to operate on (0=A, 1=B, 2=C, 3=D)"));
248 if (*selected_dac >= 4)
250 Serial.println(*selected_dac);
258 if ((selected_dac == 0) || (selected_dac == 1))
265 if (selected_dac == 0)
278 if (selected_dac == 2)
279 analogWrite(
DAC_C, pwm_code);
281 analogWrite(
DAC_D, pwm_code);
294 Serial.println(
"Python Mode");
297 if (Serial.available() > 0)
299 duty = Serial.parseInt();
314 analogWrite(
DAC_C, duty);
318 analogWrite(
DAC_D, duty);
329 float float_code, max_code;
330 max_code = pow(2, pwmBitResolution) - 1;
331 max_code = (max_code > (floor(max_code) + 0.5)) ? ceil(max_code) : floor(max_code);
332 float_code = (dac_voltage / fullScaleVoltage) * max_code;
333 float_code = (float_code > (floor(float_code) + 0.5)) ? ceil(float_code) : floor(float_code);
336 if (float_code > max_code)
337 float_code = max_code;
338 return ((uint16_t)float_code);
346 Serial.print(F(
"Type 1 to enter voltage, 2 to enter code:"));
349 Serial.println(user_input);
360 uint16_t
get_voltage(
float fullScaleVoltage, int8_t pwmBitResolution)
364 Serial.print(F(
"Enter Desired DAC output voltage: "));
366 Serial.print(dac_voltage);
367 Serial.println(
" V");
377 Serial.println(F(
"\nEnter Desired Duty Code"));
378 Serial.println(F(
"Range: DAC A/B- 0-65535(16-bit PWM)\n DAC C/D- 0-255(8-bit PWM)"));
379 Serial.print(F(
"(Format 32768, 0x8000, 0100000, or B1000000000000000): "));
381 Serial.print(F(
"0x"));
382 Serial.println(returncode, HEX);
397 Serial.println(F(
"Writing 0.5V ladder to DACs..."));
398 Serial.println(F(
"Verify VOUTA between 0.490 and 0.510"));
399 Serial.println(F(
"Verify VOUTB between 0.990 and 1.010"));
400 Serial.println(F(
"Verify VOUTC between 1.490 and 1.510"));
401 Serial.println(F(
"Verify VOUTD between 1.990 and 2.010"));
404 analogWrite(
DAC_C, 153);
405 analogWrite(
DAC_D, 204);
static void loop()
Repeats Linduino loop.
unsigned char user_command
Header File for Linduino Libraries and Demo Code.
static void setup()
Initialize Linduino.
static int16_t prompt_voltage_or_code()
Prompt user to enter a voltage or digital code to send to DAC.
static void print_prompt()
static float percentDutyCycle[4]
Full Scale Voltage.
static uint16_t get_voltage(float fullScaleVoltage, int8_t pwmBitResolution)
Get voltage from user input, calculate DAC code based on full scale voltage and PWM bit resolution...
static void menu_1_select_dac(int16_t *selected_dac)
static void pwm_16_bit(uint8_t pin, uint16_t duty)
Sets duty cycle for 16-bit PWM.
static void menu_2_set_duty(int8_t selected_dac)
Sets the duty cycle for the DAC.
static void print_title()
Prints the title block when program first starts.
static uint16_t get_code()
Get code to send to DAC directly, in decimal, hex, or binary.
static uint16_t LTC2645_voltage_to_pwm_code(float dac_voltage, float fullScaleVoltage, int8_t pwmBitResolution)
Calculate a LTC2645 duty code given the desired output voltage.
static void init_16_bit_PWM()
Initializes Pin 9 and 10 for 16-bit PWM.
static void python_program()
Used to interact with the corresponding python program.