Wixel Timer4 Problem

Hi, all
I downloaded an app(example_pwm) from Wixel github(github.com/pololu/wixel-sdk/blo … mple_pwm.c), this program is using Timer3 to generate PWM. I want to generate 4 PWM signals, so I need another timer Timer4. I changed all the Timer3 configuration to Timer4 and the program works wired(I want to test timer4 first). It shows me the reconnection problem(Wixel connection problem).The code is as following, please give me some advice.

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>

void timer4Init()
    // Start the timer in free-running mode and set the prescaler.
    T4CTL = 0b01110000;   // Prescaler 1:8, frequency = (24000 kHz)/8/256 = 11.7 kHz

    // Set the duty cycles to zero.
    T4CC0 = T4CC1 = 0;

    // Enable PWM on both channels.  We choose the mode where the channel
    // goes high when the timer is at 0 and goes low when the timer value
    // is equal to T4CCn.
    T4CCTL0 = T4CCTL1 = 0b00100100;

    // Configure Timer 1 to use Alternative 1 location, which is the default.
    PERCFG &= ~(1<<6);  // PERCFG.T1CFG = 0;

    // Configure P1_0 and P1_1 to be controlled by a peripheral function (Timer 4)
    // instead of being general purpose I/O.
    P1SEL |= (1<<1) | 1 ;


void updatePwm()
    uint16 x;

    // Set the duty cycle on channel 0 (P1_0) to 210/256 (82.0%).
	T4CC0 = 210;

    // Make the duty cycle on channel 1 (P1_1) vary smoothly up and down.
    x = getMs() >> 3;
    T4CC1 = (x >> 8 & 1) ? ~x : x;

void main()



I am sorry you are having trouble with the Wixel.

In the future, please format your posts using [code] and [/code ] tags (without the spaces) so it is more readable. You code looks OK to me; I don’t see any reason why it would interfere with the usual mechanism for getting the Wixel into bootloader mode.

To troubleshoot, please follow these steps:

  1. Disconnect the Wixel from USB.
  2. With P2_2 connected to 3.3 V, connect the Wixel to USB. This should get the Wixel into bootloader mode.
  3. Look in the Wixel Configuration Utility and see if things look OK. The status of the Wixel should be something like “No App” or “App Stopped”. If that is not the case, please tell me exactly what you see.
  4. Look in the Device Manager and find the entry for the Wixel USB Bootloader. If it is in the “Pololu USB Devices” category and does not have any kind of yellow triangle on the icon, then that is good.
  5. See if you can upload your Timer 4 PWM program to the Wixel using the “Write” button in the Wixel Configuration Utility.
  6. After uploading the program, are you able to upload it again by simply clicking the “Write” button? If not, what error messages do you see?


Did anyone try this code on his/her Wixel. Did you have the same problem. If I want to use Timer4, what should I do? Is this hardware problem?

Sorry, I just realized that Timer 4 is used by wixel.lib (one of the libraries) to implement the getMs function which gets the current time. Since you reconfigured Timer 4, the interrupt in time.c was probably not firing and the code in usb_cdc_acm.c that uses getMs to start the bootloader 70ms after it was requested was failing.

Instead of using Timer 4, I recommend that you adapt the code to use Timer 1. Timer 1 is a 16-bit timer, so it is very different from Timer 3 and you will need to read the CC2511 datasheet carefully in order to understand how to use it.

It would be possible to use Timer 4 if you really wanted to, but you would have to figure out some other way to implement the getMs function.


if you are not using the getMs or delayMs functions, just comment out those from the wixel library header files and that will make your code work.