CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

High CAN traffic causes A/D reading to increase

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

High CAN traffic causes A/D reading to increase
PostPosted: Sat Aug 08, 2015 11:48 am     Reply with quote

I think I'm facing a memory corruption issue. I have two prototype boards and they both have this issue, so I've ruled out the possibility of it being a hardware fault that is present on only one board. Running a dsPIC33FJ256GP710A, PCD compiler version 4.141.

I'm using DMA to scan and convert 7 A/D channels. Once all 7 channels have been converted, the DMA interrupt fires and my code then extracts the samples where they're processed out of an interrupt.

I'm also using DMA to handle CAN reception and transmission (only one CAN transceiver on this chip is being used).

I'm also using DMA to handle UART (UART1) transmits.

This project is based on several existing projects that all work and all incorporate some or all of the DMA A/D, DMA CAN and DMA UART transmit code.

The issue that I'm seeing with this project is that high CAN traffic (a CAN packet causes a serial transmission on the UART and a received UART packet causes a CAN packet to be created; if I disconnect the hardware that is attached to the CAN lines, effectively disabling CAN traffic, I don't see the A/D creep on channel 0) will cause my A/D channel 0 (and only channel 0) to monotonically increase over time. I should clarify: the actual A/D reading DOES NOT change, but the output of the filtering that I do on the samples creeps up. The amount of creep is directly correlated to the amount of traffic. The lines that carry the CAN traffic and the serial traffic are placed well away from the A/D lines. The A/D filtering circuitry is well separated from the CAN and serial circuitry so I don't believe it to be a crosstalk issue. Indeed, the fact that the raw sample of A/D channel 0 does not change whether there is high CAN/UART traffic is proof that this isn't an analog issue.

I don't have any overlap in the DMA buffers used by the various processes. Increasing the stack had no effect so it can't be a stack issue. The A/D DMA process is the highest interrupt level (6), with the CAN and UART transmit both being level 5. Since the A/D process is higher priority, I can't imagine how high CAN and/or serial traffic could corrupt it.

As I mentioned, I have other projects that have no A/D corruption issues that employ virtually the same code structure.

Any ideas?
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 08, 2015 2:23 pm     Reply with quote

Power supply not strong enough ? If the Vref of the ADC is Vdd having a 'lot of traffic' could drop the Vdd, thus affecting the ADC.
yeah, I know a long shot but you did ask for ideas !

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 08, 2015 3:48 pm     Reply with quote

So it's getting corrupted in your ADC filter code. What happens if you
make the local variables in the filter routine into global variables ?
Does the creep go away ?

Also, what if you do a very simple filter, instead of some complex filter ?

Also, could the problem possibly be related to non-atomic code being
generated for the adc_result variable ? This may not be an issue on
the dsPIC33 with the PCD compiler (I don't have that compiler), but
it should be checked.

Also do a Google search for this:
Quote:
dsPIC33* A/D OR ADC interrupt corrupted

and this:
Quote:
site:microchip.com/forums A/D OR ADC interrupt corruption
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Sun Aug 09, 2015 1:00 am     Reply with quote

I'd be very suspicious of erratum 14.
Obviously the probability of this rises the more CAN traffic that is being generated. Effectively you need to disable DMA at any time the CAN SFR is updated to avoid this one.
It'd result in corrupted DMA registers, which could easily give unexpected values.

It's also not clear what sample rate you are using on the ADC?. Single channel or twin channel?. Erratum 13 might apply if you are using dual channel mode.

Erratum 6 also has 'nasty' spread all over it. Wouldn't affect the ADC input, but would mean corrupted values when writing to any memory 'in use' by the DMA.

As a comment, the trap interrupts are all higher priority than the conventional interrupts. Is it possible you are getting CAN trap interrupts?.

As a comment, try lowering the priority of the ADC.

A slight delay in handling the ADC shouldn't matter, and this way round updates to registers in CAN transactions would not affect the ADC.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group