cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

 hi 

   

I have written a code for sampling two pins distinctly and feeding it to the same ADC+UART module, but only one pin connected to the AMUX is being properly sampled. for the other pin I am getting a default (very small) value in the hyperterminal screen. Please help ASAP, I have a deadline for this project.

   

Program:

   

//----------------------------------------------------------------------------

   

// C main line

   

//----------------------------------------------------------------------------

   

 

   

#include <m8c.h>        // part specific constants and macros

   

#include "PSoCAPI.h"    // PSoC API definitions for all User Modules

   

#include "stdlib.h" 

   

 

   

void main(void)

   

{

   

//  // Uncomment this line to enable Global Interrupts

   

// Insert your main routine code here.

   

int data;

   

int i; 

   

int iStatus;

   

float fScaleFactor;

   

float volt;

   

char *str2;

   

char *str3;

   

char str1[] = " approaching resolution limit ";

   

int count = 0;

   

//char * strPtr;                        // Parameter pointer

   

    

   

    UART_CmdReset();                      // Initialize receiver/cmd

   

                                          // buffer

   

    UART_IntCntl(UART_ENABLE_RX_INT);

   

Counter8_Start();                     // Turn on baud rate generator   // Enable RX interrupts

   

   

    UART_Start(UART_PARITY_NONE);         // Enable UART

   

PGA_Start(PGA_MEDPOWER);

   

//LCD_Start();

   

//LCD_Position(0,2);

   

//LCD_PrString(str1);

   

M8C_EnableGInt ;

   

ADCINC_Start(ADCINC_HIGHPOWER); 

   

//ADCINC_GetSamples(0);

   

fScaleFactor = (float)2/(float)4096;// Apply power to the SC Block

   

while(1)

   

{

   

AMUX4_Start();

   

   

count++; 

   

if((count%2)==0)

   

{

   

AMUX4_InputSelect(AMUX4_PORT0_3);

   

UART_CPutString(" from POT3 ");

   

}

   

else

   

{

   

AMUX4_InputSelect(AMUX4_PORT0_1);

   

UART_CPutString(" from POT1 ");

   

}

   

   

ADCINC_GetSamples(50);                 // Have ADC run continuously 

   

   

for(i=0;i<50;i++){ 

   

while(ADCINC_fIsDataAvailable() == 0);   // Loop until value ready  

   

data = ADCINC_iClearFlagGetData();              // Clear ADC flag and get data 

   

volt = fScaleFactor * (float)data;

   

if (volt > 1) 

   

UART_PutString(str1);

   

str2 = ftoa(volt,&iStatus);

   

UART_PutString(str2);

   

UART_CPutString("\r\n");  

   

UART_PutString(itoa(str3,data,10));

   

UART_CPutString("\r\n");  

   

UART_CmdReset();                          // Reset command buffer  

   

}

   

}

   

}

0 Likes
Reply
6 Replies
JoMe_264151
Expert II

There is a note in the datasheet that after switching the Mux you have to discard the next two samples on a PSoC1.

   

 

   

Bob

0 Likes
Reply
JoMe_264151
Expert II

...but this cannot be the only error. Would you mind to post your complete project here so that we all can have a look at? Th do so, use the "Archive Project..." function in designer and upload thee resulting archive .zip here. Use MS Internet explorer, not chrome which may not work.

   

 

   

Bob

0 Likes
Reply
ETRO_SSN583
Esteemed Contributor

For starters I would move the AMUX_Start() outside the while( 1 ) loop.

   

 

   

Regards, Dana.

0 Likes
Reply
ETRO_SSN583
Esteemed Contributor

I do not see a function prototype for "AMUX4_InputSelect();", in datasheet I

   

see "AMux_Select()" ?

   

 

   

As Bob pointed out there are delays, so you should throw away a couple of

   

samples, equivalent to these settling times -

   

 

   

0 Likes
Reply
JoMe_264151
Expert II

@Dana,

   

PSoC1! There we have MUX_InputSelect(). I hope Cypress doesn't come out with a PSoC2 or I'll get totally confused.

   

 

   

Bob

0 Likes
Reply
Anonymous
Not applicable
        It s working now, i just included a delay after the pin assignment to the mux.. thank you 🙂   
0 Likes
Reply