Main Site Documentation

G120 - RLP Audio Recording


#1

Hi everyone,

I’m using a Cobra/G120, and I’m trying to use the RLP realtime audio example to learn RLP.
https://www.ghielectronics.com/docs/151/rlp-realtime-audio-recording

The problem is when I return from the RLP function call, all the ‘captured’ data is 0.


 #define ADC_DATA_BASE_ADDRESS 0xE0034010

int GHAL_AnalogIn_Read(unsigned char channel)
{
         return ((*((int*)(ADC_DATA_BASE_ADDRESS) + channel)) >>8) & 0x3FF;
}

int ReadAudio(unsigned int *generalArray, void **args, unsigned int argsCount , 
               unsigned int *argSize)
{
         unsigned char *buffer = (unsigned char*)args[0];
         int buffer_lengh = argSize[0];
         unsigned char channel = *(unsigned char*)args[1];
         int i=3;
		 buffer[0] = 3;
		 buffer[1] = 2;
		 buffer[2] = 1;

         while(i<buffer_lengh)
         {
            buffer[i] = GHAL_AnalogIn_Read(channel);
            i++;
            RLPext->Delay(125);
         }
         return 0;
} 

If you notice, I set the first 3 spots in the buffer to 3,2,1… which does come across correctly. So the problem must be with this call:


return ((*((int*)(ADC_DATA_BASE_ADDRESS) + channel)) >>8) & 0x3FF;

I suspect the ADC_DATA_BASE_ADDRESS is not correct, or I’m not setting up the pin correctly. Can anyone help me diagnose this issue?


#2

Try to read the analog pin in c# first to make sure it is initialized. Then call rlp


#3

It didn’t work…


#4

The code is for emx which is lpc2478 but you are using g120 which is lpc1788. Please check both data sheets to find the correct base area.


#5
#define ADC_DATA_BASE_ADDRESS 0x40034000 // AD0DR0 to AD0DR7 are 0xE003-4010 to 0xE003-402C

 #define ADC_CR 0x000		//A/D Control Register. The ADCR register must be written to selectthe operating mode before A/D conversion can occur.
 #define ADC_GDR 0x004		//A/D Global Data Register. This register contains the ADCs DONE bit and the result of the most recent A/D conversion.
 #define ADC_INTEN 0x00C		//A/D Interrupt Enable Register. This register contains enable bits that allow the DONE flag of each A/D channel to be included or excluded from contributing to the generation of an A/D interrupt.
 #define ADC_DR0 0x40034010		//A/D Channel 0 Data Register. This register contains the result of the most recent conversion completed on channel 0.
 #define ADC_DR1 0x40034014		//
 #define ADC_DR2 0x40034018		//
 #define ADC_DR3 0x01C		//
 #define ADC_DR4 0x020		//
 #define ADC_DR5 0x024		//
 #define ADC_DR6 0x028		//
 #define ADC_DR7 0x02C		//
 #define ADC_STAT 0x030		//A/D Status Register. This register contains DONE and OVERRUN flags for all of the A/D channels, as well as the A/D interrupt/DMA flag.
 #define ADC_trm 0x034		//ADC trim register.
 #define SHIFT 0x4

As Gus say’s you have the wrong base address. The lpc1788 user manual is available from NXP’s website and is an essential resource if you’re working with RLP.


#6

ADC7:

return (int)(0x4003402C);

Then used the documentation to bit shift away the values I’m not interested in, divide by ADC max, and multiply by 3.3V… and boom! VOLTAGE


#7

Hi guys I noticed that this example is just reading a register to get the voltage level of the A2D but how often is this registry value refreshed?

If I need to read a value on a specific moment (not before that time), how can I make sure when the reading was taken?

I have another post where I try to manually ask for an specific reading at an specific time, but is is not stable and it always has the overrun bit on, I wondering if there is a proper way to do that.

https://www.ghielectronics.com/community/forum/topic?id=13571

Any help will be appreciated.


#8

I think you can check the status bit before you read the ADC channel.


	 int stat = (*((int*)(ADC_DATA_BASE_ADDRESS) + ADC_STAT)) & 0x007;		//.Read status of ADC's just chaneels 1, 2 and 3
		 while(stat != 0x7){
			 underFlow+=1;
			 stat = (*((int*)(ADC_DATA_BASE_ADDRESS) + ADC_STAT)) & 0x007;
		 }//Wait for it to be ready
		RLPext->Delay(3);//3uS = 333KHz Sampling - So it should be safe to read the data

#9

This could work but I just wondering, how did you find the 3uS sampling rate?
It’s the sampling rate of the analog inputs of the G120?


#10

I think the data sheet says the sampling rate is 400khz. Not sure why I reduced it to 333. Probably took into account the execution time.


#11

Thanks I will try this.