Unwanted PWM truncation

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
admic_2310931
Level 2
Level 2

Hello, 

   

I am trying to increase the resolution of my Capsense Slider PWM project from 0-255 to 0-1024. The Capsense component is working correctly to the new set maximum centroid value(1024),  however my PWM output is being truncated at 255. Verfied on an oscilloscope, I cannot get anything more than 25% duty cycle. 

   

I have been messing around with it for hours and feel like I am just missing something silly. Would you be so kind as to look over my project. I have attached the workspace bundle. 

   

 

   

 

   

Thank you, 

   

Adam

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, Adam!

   

You compare the newPosition (which you forgot to declare in the function header as uint16) with CapSense_CENTROID_MAXIMUM which is a constant of 255. So you'll never exceed that value.

   

 

   

Happy coding

   

Bob

0 Likes

Ok, got it, thank you Bob.

   

Modified section below. 

   

 

   

void handleSliderPositionUpdate(uint16 newPosition) {
    /*If finger is detected on the slider*/
    if((newPosition != CapSense_SLIDER_NO_TOUCH) && (newPosition <= CapSense_LINEARSLIDER0_X_RESOLUTION)) {
        /* Write slider position to PWM output compare register*/
        PWM_WriteCompare(sliderPos);
        bool pinStatus = (sliderPos >= 30) ? 1 : 0;
        Pin_ENABLE_Write(pinStatus);
    }
}

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Looks a lot better now 😉

   

 

   

Bob

0 Likes