thefloe

Getting PWM to work

7 posts in this topic

Hi,

 

 

First of all: I started working with my Papilio Pro again and I really like how things developed here! I really like the DesignLab and how easy it easy to connect things to your own blocks! Thanks.

 

To verify some custom hardware connected to the board I need to create some square wave signal with some MHz. As neither analogWrite nor the PWM functions in the Timer class are working / present I tried writing to the registers directly (inspired by some forum post here) also does not toggle the PIN (WB12):

#include "register.h" #define FREQUENCY 100000#define SW1  WB12void setup(){  pinMode(SW1, OUTPUT);  pinModePPS(SW1, HIGH);  outputPinForFunction(SW1, IOPIN_TIMER0_OC);  TMR0CNT = 0;  TMR0CMP = (CLK_FREQ / FREQUENCY) - 1;  TMR0CTL = _BV(TCTLENA)|_BV(TCTLDIR)|_BV(TCTLCCM);  TMR0PWMLOW(0) = 0;  TMR0PWMHIGH(0) = 200;  TMR0PWMCTL(0) = 1;} 

But for now the pin stays low...

Share this post


Link to post
Share on other sites

Hello, it looks like I need to make a tutorial for using PWM in DesignLab. I will try to make one this afternoon.

 

Jack.

Share this post


Link to post
Share on other sites

In the meantime, there is a PWM in the Robot_Control_Library and an example of using it in the ColorCrossFader sketch in that library. 

 

Jack.

Share this post


Link to post
Share on other sites

Hi Jack,

 

Thank you, got everything working for PWM (actually I just needed it to generate signals to verify other parts of the VHDL design).

 

Tobias

Share this post


Link to post
Share on other sites

Excellent, I'm glad to hear that. By the way, there is a wave form generator under the Benchy section that you might find useful too.

 

Jack.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now