1:29 pm
October 20, 2016
Hi
I’m working on a setup using a Ardoino uno and a i2C display
The plan is to measure a frequency up to 300Hz and display the frequency on the LCD
At the same time I need to generate a 25Khz PWM signal (adjustable from 0-100%) and show the PWM % on the LCD
I already have this setup to work with the LINX / Arduino but would like a standalone system without a PC.
But how do I do this with the Arduino Compatible Compiler for LabVIEW?
This is the code I’m using to generate a 25Khz PWM:
// PWM output @ 25 kHz, only on pins 9 and 10.
// Output value should be between 0 and 320, inclusive.
void analogWrite25k(int pin, int value)
{
switch (pin) {
case 9:
OCR1A = value;
break;
case 10:
OCR1B = value;
break;
default:
// no other pin will work
break;
}
}
void setup()
{
// Configure Timer 1 for PWM @ 25 kHz.
TCCR1A = 0; // undo the configuration done by...
TCCR1B = 0; // ...the Arduino core library
TCNT1 = 0; // reset timer
TCCR1A = _BV(COM1A1) // non-inverted PWM on ch. A
| _BV(COM1B1) // same on ch; B
| _BV(WGM11); // mode 10: ph. correct PWM, TOP = ICR1
TCCR1B = _BV(WGM13) // ditto
| _BV(CS10); // prescaler = 1
ICR1 = 320; // TOP = 320
// Set the PWM pins as output.
pinMode( 9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop()
{
// Just an example:
analogWrite25k( 9, 110);
analogWrite25k(10, 210);
for (;;) ; // infinite loop
}
5:36 pm
March 12, 2015
Since you need to access the timer registers to adjust the frequency, there are no built in functions to do that directly. The best approach would be to make a custom LabVIEW library to implement the C code above. You can do this by wrapping an Arduino Library or just the C code with LabVIEW VIs and the Arduino Compatible Compiler for LabVIEW. Take a look at the help manual section titled "Porting an Arduino Library to the Arduino Compatible Compiler for LabVIEW". There are several examples on this forum as well. You can either create a simple Arduino library around the code above and call that from LabVIEW, or possibly just call the C code above directly through a custom LabVIEW library you create.
20
1 Guest(s)