Jump to content
godric

CC3200 Wifi and analogRead

Recommended Posts

Hi,

I have a problem with analogRead and Wifi.begin. I'm using CC3200 and Energia to test. I connect one potentiometer to Pin_60 (ADC_CH3) and a PIR sensor to Pin_50. Here comes the joke.

 

If i try to read the values :

 

a= analogRead(24);

b= digitalRead(30);

 

the sketch works perfectly. But if i include the Wifi library, and I write Wifi.begin() in the setup, the values read aren't correct.

 

What happen here? Are there something i'm forgetting? Affect Wifi to ADC?

Share this post


Link to post
Share on other sites

There is a strange issue with WiFi and analog. Each analogRead() enables / disables the ADC which flushes the FIFO. For some reason, when WiFi is enabled, the FIFO sometimes does not get flushed. The only way around this is to read the ADC multiple times discarding the first 4 reads. Below is a code snip that should help you work around it. The next release of Energia will do this inside the analogRead() and hide this "bug" from the user.

analogRead(2);  // discard
analogRead(2);  // discard
analogRead(2);  // discard
analogRead(2);  // discard
int sensorValue = analogRead(2);  // Read ADC

Share this post


Link to post
Share on other sites

Hi,

I'm a new member in this forum, and this forum is being very usefull for me to start using cc3200 launchpad with Energia.

 

I'm currently facing a problem regarding the analogRead() function, namely with channel 0 (IC Pin 57, BP P3.3 or 23).

When I execute analogRead(2), analogRead(6) and analogRead(24), the value retrieved is correct. With analogRead(23) I always get 4095. 

I found that this pin is shared with FTDI, and after programming I changed the Jumper 6 position to route the signal to the BP header.

 

Anyone with same problem? Ideas?

 

Thanks!

Miguel

Share this post


Link to post
Share on other sites

I have a feeling this is an Energia issue. I'm looking for a solution. My theory is that energia may "Automatically" enable default serial pins in a certain way that causes this to happen. If you try to do PinTypeADC(A0, 0xFF), then the system will halt at that line. I'm trying to read all 4 ADCs at high speed and I need them all to work.

 

I really hope its not the case that the RX line is automatically frying the ADC A0 just because its hooked up initially. That would be incredibly stupid.

Share this post


Link to post
Share on other sites

Hi,

 

Same issue for me.

I have an ISR running at 8KHz to sample one of the analog channels. When I collect a 100 samples I transmit them in a UDP packet.

 

It's clear when I call WiFI.begin the analog samples during that period get corrupted. Looking at the data (and on the scope) to me it looks like the pin configuration is being changed from analog to something else and then later back again to analog. This is in line with Sean's comment above: "My theory is that energia may "Automatically" enable default serial pins in a certain way that causes this to happen."

Unfortunately multiple analogReads isn't really a solution as in my view all it's doing is causing a delay until the pin config has changed back and high speed sampling will therefore always be restricted.

(In short for debug we need to look if the CC3200 pin config register is accidentally being manipulated with Wifi.Begin)

 

If there are any further updates on this issue could anyone please post.

I'll search through the forum messages further and if not already done so look to raise a ticket. 

 

Stuart

Share this post


Link to post
Share on other sites

Further update on this issue.

 

The intermittent corruption I see on the scope for the analog inputs is at a very low voltage and look like 'serial data bits' i.e. not fast rise and fall times but square on top. Difficult to tell but I'd say each bit around 100us duration, probably co-incidence but that is close to 9600 baud ??? It only happens after Wifi.begin has been called.

 

Actually all 4 analog inputs exhibit the same behaviour and what's more simultaneously ! The problem is more evident  when I'm transmitting UDP data however even when I stop transmitting there is what looks like a very short signal burst at roughly 30HZ (perhaps some handshake that's continuous to say the link is alive ?).

Note if you only require low rate sampling and put any significant capacitor to GND the corrupted signal is smoothed out and you don't see it. Unfortunately no good however for higher rate sampling. In my case 8KHz where the audio I sample gets badly impaired.

My guess is that the WIFI library calls the Energia stream class and somewhere along the way the absolute addresses which control the CC3200 port / multiplexer options are incorrectly set. I don't have the depth of knowledge on the Energia s/w to delve deeper at this time.

If any Energia guru who understands the WIiFi library could shed any light there's a few of us I believe would be very grateful. Thks.

Stuart

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×