PWM at 25kHz + Frequency counter | Arduino Compatible Compiler for LabVIEW Discussions | Forum


Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 4 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
PWM at 25kHz + Frequency counter
November 4, 2016
1:29 pm
New Member
Forum Posts: 2
Member Since:
October 20, 2016
sp_UserOfflineSmall Offline


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;


       case 10:

           OCR1B = value;



           // no other pin will work





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


November 4, 2016
5:36 pm
Forum Posts: 304
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

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.

Forum Timezone: UTC 0

Most Users Ever Online: 33

Currently Online:
6 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

John: 18


Dan6077: 11

Member Stats:

Guest Posters: 0

Members: 80

Moderators: 0

Admins: 3

Forum Stats:

Groups: 1

Forums: 2

Topics: 58

Posts: 289

Newest Members: Geraldkix, ThomasSoogs, Angelvor, AngelaMuh, Nsneilohone

Administrators: geadmin: 5, filipealtoe: 35, Steffan: 89