Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > ADC and PWM interrupt

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



ADC and PWM interrupt
Moderator:
ARVI

Post Reply
Follow this topic



ADC and PWM interrupt

Beaver posted on 05 Jan 2011 8:48 PM PST

1 Forum Post

Hello,

I am a newbie to Psoc 1 and I have started writing some codes but it doesn't seem to work. What I am trying to do is: connect voltage supply to the Psoc 1 as an input and when I change the input voltage it will output a different frequency PWM on the oscillascope. However, on my oscillascope it only shows 5V DC. I have attached my codes below, could anyone please help me.

Thank you!

 

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#pragma interrupt_handler ADCINC14_1_ISR

void ADCINC14_1_ISR(void)
{
 int ADC_Result;
 int pwmValue,pulseWidth;
 
 ADCINC14_1_GetSamples(0);
 ADC_Result = ADCINC14_1_iGetDataClearFlag();
 ADCINC14_1_StopAD();
 
 pwmValue = ADC_Result/300;
 
 /*Set period*/
 PWM16_1_WritePeriod(pwmValue);
 /*set pulse width to generate a 50% duty cycle*/
 pulseWidth = pwmValue/2;
 PWM16_1_WritePulseWidth(pulseWidth);
 /*Disable Interrupt*/
 PWM16_1_DisableInt();
  
    return;
}

void main()
{   
  //Enable Global Interrupt
 M8C_EnableGInt;
 
 //Start ADC
 ADCINC14_1_Start(ADCINC14_1_HIGHPOWER);
 
  /*start the PWM16!*/
  PWM16_1_Start();
 
 
 
}




Re: ADC and PWM interrupt

graa posted on 20 Feb 2011 08:25 AM PST
Cypress Employee
275 Forum Posts

The ADCINC14 has it's own ISR generated by PSoC Designer.  The ISR has code that is necessary for the ADC to function correctly.  So, creating your own ISR for the ADC is not the correct method.  Instead, in the main loop, poll for the ADC data to be availabel and update the PWM period based on this value.  Try the following code instead.

void main()
{

    //Enable Global Interrupt
    M8C_EnableGInt;
 
    //Start ADC
    ADCINC14_1_Start(ADCINC14_1_HIGHPOWER);
 
    /*start the PWM16!*/
    PWM16_1_Start();

    while(1)
    {
        while(!(ADCINC14_fIsDataAvailable());
        ADC_Result = ADCINC14_iGetDataClearFlag();
        pwmValue = ADC_Result / 300;
       
        PWM16_WritePeriod(pwmValue);
        PWM16_1_WritePulseWidth(pwmValue >> 1);
    }
}

Best Regards,
Ganesh






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: KXP; Secondary Owner: VWA; Sunset Date: 01/01/20