SPI EEPROM Record and Playback on Explorer 16

Post Reply
resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

SPI EEPROM Record and Playback on Explorer 16

Post by resodad » Fri Apr 23, 2010 2:04 am

Hello,
I would like to record a PWM signals and reproduce ("play back") later. These are radio control signals: 20ms fixed period, high time varies from 0.5 to 2.5 ms. My proposal is to record the high times to EEPROM on board the Explorer 16. This EEPROM is already connected to SPI2. A toggle switch e.g. B2 will control whether I am resording or playing back.

Questions:
1. Can I use eeprom in this way to record a list of numbers and then go back to the beginning of the list and read them back?
2. Should I use interrupt SPI block? see the attachment SPIwork1
2. Maybe I can do this without interrupt, see attachment SPIwork2
3 simulink gives error:
Error building Real-Time Workshop target for block diagram 'SPIwork2'. MATLAB error message: The following error occurred processing the System Target File '': SubSystem block does not have a parameter named 'RTWGenSettings'.

Thanks,
John
Attachments
SPIwork2.mdl
(34.91 KiB) Downloaded 1045 times
SPIwork1.mdl
(33.39 KiB) Downloaded 996 times

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: SPI EEPROM Record and Playback

Post by LubinKerhuel » Mon Apr 26, 2010 1:56 am

Hi John,
resodad wrote:1. Can I use eeprom in this way to record a list of numbers and then go back to the beginning of the list and read them back?
Should be Ok.

2)3)4)
You can't have two interrupt driven SPI blocks, except perhaps very special case (here is not the case). Even it ir was working, this would not be good for what's you are doing (as interrupt SPI block may be executed several times within one time-step).

Thus, you should the other SPI block.
the model SPIwork2 is compiling on my system.


Anyway, I get another error : Play back subsystem need a uint8 to uint16 converter between SPI and OC blocks.
Idem in Record sybsystem between IC and SPI blocks.

Could you provide details about your error (copy all compiling message, blockset version, matlab version, any useful information to make me able to reproduce the problem)

Lubin

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: SPI EEPROM Record and Playback

Post by resodad » Tue Apr 27, 2010 10:12 pm

Thanks Lubin, Your info about interrupts helped me along.
There were several problems with the previously posted model SPIwork2.
I simplified to make sure I can do an easy task first.

Easy Task: Measure PWM input using IC2 and immediately duplicate it on OC2.
This is running--output tracks input perfectly! Well, there is latency, but otherwise perfect.
See the model ic_to_oc_v2.mdl and the description IC to OC.doc in the first attachment.
Question: Can I specify which timer to use for a peripheral?
e.g. I want to can I use timer 3 for both IC2 and OC2.
Question: Can I specify a 32-bit combined timer 2/3?

Difficult Task: write a stream to EEPROM over SPI
See attached model SPIwork3.mdl
I have LED indicators on Explorer16 for record and playback, these work OK
In record mode the IC2 data looks correct viewed over UART
In playback mode, UART shows nothing but zeros
I am not sure if this is writing to SPI bus:
The /CS pin on the EEPROM is constantly low, and a clock signal is present, but I do not see any data signals.

As always thanks so much for your expert help.
John
Attachments
SPIwork3.zip
(10.66 KiB) Downloaded 1018 times
inputCapture_to_OutputCompare.zip
(437.9 KiB) Downloaded 1086 times

Ender
Posts: 38
Joined: Thu Oct 09, 2008 5:20 pm
Location: Phoenix USA _ Grenoble Fr

Re: SPI EEPROM Record and Playback on Explorer 16

Post by Ender » Wed Apr 28, 2010 7:46 pm

Hi John,

In the SPI Config block, you have to enable the output "SDO enable", with the scope check the data on the pin 5 call SI of U5, or on the pin 12 of your Dspic it should be work now...
If it doesn't work update here another model more simple, with just the enable on D12 and to send a constant on the SPI output. Give us your Mathlab and blockset version please.

Are you building something like a universal remote control ?

Lubin what the utility to disable the SDO ?

Thierry

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: SPI EEPROM Record and Playback on Explorer 16

Post by resodad » Wed Apr 28, 2010 8:43 pm

Hello Thierry,
I will do that. Also, I had a look at 24LC256 data sheet.I see that I have to send EEPROM WREN and WRITE commands and then address before I write to EEPROM, so I have some work to do before I post.
Thanks,
John

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: SPI EEPROM Record and Playback on Explorer 16

Post by LubinKerhuel » Wed Apr 28, 2010 10:53 pm

Ender wrote:Lubin what the utility to disable the SDO ?
Well, if you don't use it ? Isn't there some chip that are not waiting anything before sending data (thus receive on SDI) ? Perhaps to read data on a bus ?
Anyway, this option is present on microchip microcontrôller, I just give acces to it on the blockset. I never had use of it yet !

Jon, we'll wait your next post...
Lubin

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: SPI EEPROM Record and Playback on Explorer 16

Post by resodad » Wed Apr 28, 2010 11:11 pm

Lubin, Thierry:
Ender wrote:Are you building something like a universal remote control ?
No, it's not a universal remote; I am trying to record and reproduce radio controlled car signal wave forms.
Ender wrote:you have to enable the output "SDO enable"
What is "SDO enable" for?
Here is my attempt at writing a single value to address 21 on the EEPROM and reading back. It reports only zeros. see attachment.
Pin 5 of U5 on the Explorer16 DOES show the data. I can see the pattern of the data 1234 decimal, 10011010010 binary, as well as the WREN and WRITE commands and the address on oscilloscope.
During attempted read operation, read request and address appear on SI pin, but NOTHING on SO pin.
Matlab is R2009BSP1
blockset is Version 3.1a 16-Mar-2010 For Matlab 7.8 R2009a
Lubin should I upgrade blockset?
Cheers,
John
Attachments
SPIwriteRead.zip
(14.08 KiB) Downloaded 1026 times

Ender
Posts: 38
Joined: Thu Oct 09, 2008 5:20 pm
Location: Phoenix USA _ Grenoble Fr

Re: SPI EEPROM Record and Playback on Explorer 16

Post by Ender » Thu Apr 29, 2010 2:02 am

LubinKerhuel wrote:
Ender wrote:Lubin what the utility to disable the SDO ?
Well, if you don't use it ?

Lubin
Ho yeh, I'm silly! :lol:
I Have used the SPI one time, 8 years ago, and for me it was a big shift register so simple that you better have to loop the data from in to out all the time anyway you have nothing to write when you are reading the register.
And I never see SPI peripherals using just the enable and clock to return data on their SO, but you right and the PIC could be in slave so just to use his SI to be controled as a sink. Thanks.

Ender
Posts: 38
Joined: Thu Oct 09, 2008 5:20 pm
Location: Phoenix USA _ Grenoble Fr

Re: SPI EEPROM Record and Playback on Explorer 16

Post by Ender » Thu Apr 29, 2010 4:32 am

John, I didn't try, just take a peek on the datasheet :

The Read and Write instructions have to be on 8 bits, so I guess you have to change all your model to use the 'SPI config' as 8 bits data size.

Doesn't matter but I think you do not need a WRDI at the end of a write sequence.

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: SPI EEPROM Record and Playback on Explorer 16

Post by resodad » Thu Apr 29, 2010 8:26 pm

Lubin and all,
I made that change Thierry--8-bit addresses. Also I made the data 8 bits and the SPI data setting 8 bits instead of 16.
It is still not working. I will attach scope traces showing /CS, CLOCK, and both DATA lines. These traces look good to me: from bottom to top: /CS, DATA out, DATA in, CLOCK. There is no data out.
What is wrong?

I will compare to signals produced by working C program (program also atached).
Question: is there an easy way to handle 16-bit to 2x 8-bit and vice versa? I handled it one way to send UART TX, but am wondering if there is a simpler way.
Attachments
SPI Master EEPROM dcPIC.zip
C code for EEPROM Write Read
(247.24 KiB) Downloaded 1090 times
SPI oscilloscope.zip
(32.71 KiB) Downloaded 1026 times
SPIwriteRead_v2.zip
hex and .mdl file
(13.51 KiB) Downloaded 1026 times

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: SPI EEPROM Record and Playback on Explorer 16

Post by resodad » Thu Apr 29, 2010 8:59 pm

OH!
I changed commands to 8 bits--right
but also:
changed address to 8 bits :WRONG!

Stand By
John

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: SPI EEPROM Record and Playback on Explorer 16

Post by resodad » Thu Apr 29, 2010 9:26 pm

Still not working :(
Latest model attached.
john
Attachments
SPIwriteRead_v3.zip
(14.02 KiB) Downloaded 1015 times

Ender
Posts: 38
Joined: Thu Oct 09, 2008 5:20 pm
Location: Phoenix USA _ Grenoble Fr

Re: SPI EEPROM Record and Playback on Explorer 16

Post by Ender » Thu Apr 29, 2010 11:59 pm

I didn't check everything but the principle seem now good for me. Good idea to add the traces 8).

The clock edges are rising while the data are changing too. The memory chip take the data on the rising edge clock no on the state.
Inside the Lubin SPI config block, it seem for me you can change the clock to be active on a state Low or High state and sample on midle of the data... it should be fall in work...

Ender
Posts: 38
Joined: Thu Oct 09, 2008 5:20 pm
Location: Phoenix USA _ Grenoble Fr

Re: SPI EEPROM Record and Playback on Explorer 16

Post by Ender » Fri Apr 30, 2010 12:10 am

Lubin, :idea:

On future versions, you maybe change the form inside the Configure SPI mask by:
- the currently 'Sample Phase' by 'clock synchronization' with 'edge' and 'state' as choices.
- and Clock Active with 'State high or Rising' and 'State Low or Falling' as choices.

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: SPI EEPROM Record and Playback on Explorer 16

Post by resodad » Fri Apr 30, 2010 4:11 pm

Thierry thanks for the help.
Program is working to write then read from EEPROM. See atachments.
Attachments
Write_Read_EEPROM.zip
Description, .mdl, and .hex files
(415.33 KiB) Downloaded 1134 times

Ender
Posts: 38
Joined: Thu Oct 09, 2008 5:20 pm
Location: Phoenix USA _ Grenoble Fr

Re: SPI EEPROM Record and Playback on Explorer 16

Post by Ender » Fri Apr 30, 2010 6:43 pm

:D
resodad wrote:Lubin and all,
Question: is there an easy way to handle 16-bit to 2x 8-bit and vice versa? I handled it one way to send UART TX, but am wondering if there is a simpler way.
I didn't see which method you are using but I would use the Matlab instruction : 'Bitsliceget' and 'Bitconcat', and all instructions like 'bitshift' too, which are close of C code equilalent instructions.

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: SPI EEPROM Record and Playback on Explorer 16

Post by LubinKerhuel » Fri Apr 30, 2010 7:19 pm

Hi Jon, Thierry

Jon, good to see EEPROM read-write working on Explorer 16. I may place a link to this demo from one of the wiki page if you're Ok (for example on the example page)

Thierry,
With simulink, you can handle conversion 8 to 16 bits using shift blocks and lobgical operator. Even if it is not much practical to do it with theses blocks, it is compiled in a quite pretty way.)
You may also use the embedded matlab function block to make your conversion.
There are also solutions with the Convert block using the Store integer (SI) options (more tricky, but interresting to see how theses blocks works when used with the SI option).
You may find pretty example from the ECAN peripheral (look under mask) than Bryant mairs has done. you may find a link thereto download it.

With matlab script, I have nothing more to propose than instructions you provided. I typically use the (bitand, bitshift...) instructions, or worse : divisions and additions...
Perhaps you may find better way within the fixed point toolbox.

Lubin

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: SPI EEPROM Record and Playback on Explorer 16

Post by resodad » Sat May 01, 2010 12:07 pm

Hi Lubin,
LubinKerhuel wrote:place a link to this demo
That would be great. Then when I forget :? how to do it, I can easily find it.
Cheers,
John

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests