- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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();
}
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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