FORUM TOPIC · READ ONLY

SPI EEPROM Record and Playback on Explorer 16

SPI EEPROM Record and Playback on Explorer 16

Forum : dsPIC Peripherals

18 message(s) · archive en lecture seule

resodad
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

Pièce jointe : SPIwork1.mdl

Pièce jointe : SPIwork2.mdl

LubinKerhuel

Re: SPI EEPROM Record and Playback

Hi John,


Citation : resodad
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

Re: SPI EEPROM Record and Playback

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

Pièce jointe : SPIwork3.zip

Pièce jointe : inputCapture_to_OutputCompare.zip

Ender

Re: SPI EEPROM Record and Playback on Explorer 16

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

Re: SPI EEPROM Record and Playback on Explorer 16

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

Re: SPI EEPROM Record and Playback on Explorer 16

Citation : Ender
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

Re: SPI EEPROM Record and Playback on Explorer 16

Lubin, Thierry:
Citation : Ender
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.
Citation : Ender
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

Pièce jointe : SPIwriteRead.zip

Ender

Re: SPI EEPROM Record and Playback on Explorer 16

Citation : LubinKerhuel
Citation : Ender
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

Re: SPI EEPROM Record and Playback on Explorer 16

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

Re: SPI EEPROM Record and Playback on Explorer 16

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.

Pièce jointe : SPIwriteRead_v2.zip

Pièce jointe : SPI oscilloscope.zip

Pièce jointe : SPI Master EEPROM dcPIC.zip

resodad

Re: SPI EEPROM Record and Playback on Explorer 16

OH!

I changed commands to 8 bits--right

but also:

changed address to 8 bits :WRONG!



Stand By

John
Ender

Re: SPI EEPROM Record and Playback on Explorer 16

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

Re: SPI EEPROM Record and Playback on Explorer 16

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

Re: SPI EEPROM Record and Playback on Explorer 16

Thierry thanks for the help.

Program is working to write then read from EEPROM. See atachments.

Pièce jointe : Write_Read_EEPROM.zip

Ender

Re: SPI EEPROM Record and Playback on Explorer 16

:D


Citation : resodad
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

Re: SPI EEPROM Record and Playback on Explorer 16

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

Re: SPI EEPROM Record and Playback on Explorer 16

Hi Lubin,
Citation : LubinKerhuel
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