Getting PWM to work


thefloe

Recommended Posts

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...

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.