- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
}
}
}
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is a note in the datasheet that after switching the Mux you have to discard the next two samples on a PSoC1.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
...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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For starters I would move the AMUX_Start() outside the while( 1 ) loop.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Dana,
PSoC1! There we have MUX_InputSelect(). I hope Cypress doesn't come out with a PSoC2 or I'll get totally confused.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content