View previous topic :: View next topic |
Author |
Message |
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
Multiple A/D conversion |
Posted: Mon Mar 28, 2011 1:07 pm |
|
|
Hello...
Am using DSPIC30f4012 in order to take 2 analog inputs and make some feature extraction for these inputs and then enter these values to neural network...But am worry about the time of calculation since in the neural network there is exponential and tangent functions.
If the time of calculation was big then many values in the signal will not be digitized and will be lost.
Am thought to put 2 microcontrollers 16f818 in order to make the A/D and make the calculation for the extracted features(rms value, slope changes, zero crossing..) and then send them to the DSPIC using SPI and the DSPIC will make the calculation for the neural network mathematical equation...
Please share me your ideas. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Mar 28, 2011 6:39 pm |
|
|
Well, you've got some math to do !
What is the overall system time factor? IE how fast MUST the system execute to get data and do something with it?Single chip solutions usually work better than 'distributed processors' when looking at the big picture,providing the total design is well laid out from the start.Cost of parts,R&D time and money,product size, time to market,etc. all factor into the equation.Time critical functions usually can be optimized in assembler.Knowing your chips strengths and weeknesses can make or break a project.Using integer math is a lot faster than floating point.Available memory RAM, ROM,stack is very important.
First cut code for the 818s to do the 'frontend' work as well as the SPI communications to the DSPIC. Be sure to include some kind of 'data valid' for the interPIC communications. Same thing for the DSPIC doing the neuralnet stuff.Be 100 % sure the data from the 818s is true. This usually involves using a 'checksum'. Also you'll need some kind of code to verify that both the frontend PICs are still alive and operating correctly.If one 818 fails or 'glitches', HOW do you handle that situation, yes, it WILL happen..btdt !
Once you get all that figured out, look at the time involved doing it as compared to having just the ONE DSPIC doing all the work.
'Simple' things like, are both 818s using the same Vref for their ADCs? You might want a common high precision Vref source which of course costs money. Then there's the cost of the 818 PICs themselves, PCB space,regulators, bypass caps,board design time,etc.
There's probably 100 or more factors to consider, so start with what you know, overall time for the 'main system loop' and build in blocks, optimise each block as required, then look for ways to increase throughput either by reusing common code, type of math, lookup tables vs. formulae, etc. |
|
|
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
|
Posted: Tue Mar 29, 2011 1:22 pm |
|
|
Thank you very much!
I have a window of 250 ms to acquire data, and after this window processing will take place (using the neural network). I want the processing to be as fast as possible in order not to lose data from the signals.
I don't know how to calculate time for each instruction to be accomplished, such as addition, subtraction multiplication, how can I calculate these values? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
iMakeRobots
Joined: 28 Mar 2011 Posts: 1 Location: Cali
|
|
Posted: Tue Mar 29, 2011 5:40 pm |
|
|
You could also set an extra I/O high just before you do start the conversion/math and clear it when it finishes. Then just look at it on a scope. The stop watch function is nice but this will give you the real world answer. This is especially usefull when you have any external interrupts that will be executing as well since you would have to setup a stimulus file in MPLAB to even come close to getting an accurate time with the stop watch. _________________ I like Robots! |
|
|
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
|
Posted: Thu Mar 31, 2011 7:06 am |
|
|
Thanks a lot, its very useful.
I tried it in 2 different codes one in assembly and the other in C, and i figured out that the it takes 3 times minimum time more in c to make the same function done in assembly!! |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Mar 31, 2011 9:34 pm |
|
|
iMakeRobots wrote: | You could also set an extra I/O high just before you do start the conversion/math and clear it when it finishes. Then just look at it on a scope. The stop watch function is nice but this will give you the real world answer. This is especially usefull when you have any external interrupts that will be executing as well since you would have to setup a stimulus file in MPLAB to even come close to getting an accurate time with the stop watch. |
I've done this before.. pretty handy.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Mar 31, 2011 9:39 pm |
|
|
hisham.i wrote: | Thanks a lot, its very useful.
I tried it in 2 different codes one in assembly and the other in C, and i figured out that the it takes 3 times minimum time more in c to make the same function done in assembly!! |
That really depends on how you're writing your 'C' code.
I remember an example on the 8bit PIC's where
if you overlay a struct onto a PORT and then use bitfield manipulation to toggle bits with this:
portb.bit0 ^= 1;
The compiled code is pretty lengthy *when compared* to just using the bit_toggle function or the assembly BTG instruction.
But without digging or asking, you may not know that.
So why not show us your code so that we might offer possible optimizations?
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
|
Posted: Fri Apr 01, 2011 2:33 am |
|
|
I tried to make z=x+y instruction in c and i tried to make ADD in assembly.
While am reading the datasheet of dspic30f4012, in the A/D section i read that i can make multiple samplings in one instruction cycle then i can start conversion and the values are registered in Buffer Register. This can be done if i changed the value of SIMSAM bit.
how can i change such value in ccs?.. i read the function in 30f4012.h file but i didn't see any function which can allow me to access such a feature. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Apr 01, 2011 9:13 am |
|
|
#bit SIMSAM=REGADDR.BITNO
Then with suitable bitno, and regaddr, you can say 'SIMSAM=1', and the compiler will set the bit, or SIMSAM=0, and it'll clear it.
Best Wishes |
|
|
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
|
Posted: Mon Apr 11, 2011 12:25 pm |
|
|
Hello again...
I have some questions...
1-can i program dspic with pickit2, or K128 programmer?
2-if i make conversion on 10 bit, when i use the read_adc function does it give me the result of the 10 bits read or 8 bit?
3-suppose that i convert an analog input over 10 bits, when i want to send this data over serial port(UART), i have to send 2 data bytes in order to read the converted data?
Thanks in advance |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 11, 2011 2:03 pm |
|
|
Quote: | can i program dspic with pickit2, or K128 programmer?
|
This is a Google question. Use Google to search for this:
Quote: |
pickit2 supported devices |
Quote: |
if i make conversion on 10 bit, when i use the read_adc function does it
give me the result of the 10 bits read or 8 bit?
|
This is a CCS manual question. Download the manual for your compiler,
and look in the "read_adc" section. Look at the "Returns" section that
describes the value returned by the function.
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
http://www.ccsinfo.com/downloads/PCDReferenceManual.pdf
Quote: |
suppose that i convert an analog input over 10 bits, when i want to send
this data over serial port(UART), i have to send 2 data bytes in order to
read the converted data?
|
If you have two bytes of data, and your transmitter device only sends
data in bytes, then how many bytes do you have to transmit ? |
|
|
|