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

Avatar
Please consider registering
guest
sp_LogInOut Log In sp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 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
Avatar
pmn
New Member
Members
Forum Posts: 2
Member Since:
October 20, 2016
sp_UserOfflineSmall Offline

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

}

November 4, 2016
5:36 pm
Avatar
Steffan
Admin
Forum Posts: 408
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: 100
Currently Online:
22
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
miche91: 33
scottj: 28
scadao: 23
Member Stats:
Guest Posters: 5
Members: 202
Moderators: 0
Admins: 3
Forum Stats:
Groups: 1
Forums: 2
Topics: 266
Posts: 1222
Newest Members:
pujacontrol
Administrators: geadmin: 22, filipealtoe: 96, Steffan: 356