Getting PWM to work

Recommended Posts




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

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