Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How can I solve strange problem with global variables?

Status
Not open for further replies.

electrodarkness

Member level 1
Member level 1
Joined
May 2, 2010
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Ganesti, Transylvania, Romania
Visit site
Activity points
1,649
Hello everyone! I'm designing a guitar multi-effect processor with pic32mx460f512l uC in XC32. I'm using AD7476 SPI ADC and MCP4921 SPI DAC. I managed to read and write some values so far from the main program, but when I'm using an interrupt routine for SPI, inside the routine the ADC data exists, outside it is 0. I've tried everything I could think of ( declaring the global volatile, etc.) with no luck so far. This problem is killing me, so any help would be really appreciated!
(I've attached the project files).
 

Attachments

  • gfx.X.rar
    3.5 KB · Views: 88

I believe the correct delaration syntax is
Code:
volatile unsigned short int rFlag = 0;
instead of
Code:
unsigned short int volatile rFlag = 0;
Volatile is in fact essential, otherwise the flag would be probably removed in the main loop code by optimization.

My suggestion is to look at the generated code and to debug the application at assembly level. If the rData gets actually lost in the code, you can see why.

My guess is that the problem is of a different kind, somewhere between the multiple ISRs accessing the SPI interface. I didn't try to get behind the implemented logic without knowing the circuit diagram and a description of intended operation.
 
Last edited:
Thanks for the suggestion. I've generated the listing file, and tried to debug the circuit at assembly level, but couldn't find the problem( maybe because I'm relatively new to the assembly language) - I could only spot that is uses the same address in the interrupt and in the main program . The used circuit board is the DIGILENT CEREBOT MX4ck board. Now I'm really thinking of making everything in the main program - although it wouldn't be a wise idea.
 

Attachments

  • listing.txt
    279 KB · Views: 45
Last edited:

I think I found the problem. I was using both SPI send and receive with interrupt, and the program got stuck in the interrupt routine. Now I'm working with Timer1 interrupt only for generating the 50kHz sampling frequency, and using SPI send/receive without interrupt - with a little strange problem: when debugging with no ADC I get 0x0FFF, and with ADC around 0x00A7 which is normal, but in real-time I get 0xFFFF with no ADC and 0x0000 with ADC on ( ADC input left floating, real-time running is tested with uart terminal).


Edit : now the dc value is 0x0024 in both cases, but it won't measure my 1Hz sine wave. I would really need some help, cause now there is no problem with interrupt, neither with SPI chipselect bits. Somehow it just doesn't read my signal in(I've also updated the attached files). Thanks in advance!
 

Attachments

  • gfx.rar
    86.9 KB · Views: 69
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top