SPI EEPROM Record and Playback on Explorer 16
SPI EEPROM Record and Playback on Explorer 16
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
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 1135 times
-
- SPIwork1.mdl
- (33.39 KiB) Downloaded 1085 times
-
- Site Admin - Expert
- Posts: 616
- Joined: Wed Mar 07, 2007 11:23 pm
- Location: Bayonne- France
- Contact:
Re: SPI EEPROM Record and Playback
Hi John,
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
Should be Ok.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?
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
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
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 1089 times
-
- inputCapture_to_OutputCompare.zip
- (437.9 KiB) Downloaded 1176 times
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
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
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
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
-
- 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
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 ?Ender wrote:Lubin what the utility to disable the SDO ?
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
Re: SPI EEPROM Record and Playback on Explorer 16
Lubin, Thierry:
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
No, it's not a universal remote; I am trying to record and reproduce radio controlled car signal wave forms.Ender wrote:Are you building something like a universal remote control ?
What is "SDO enable" for?Ender wrote:you have to enable the output "SDO enable"
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 1115 times
Re: SPI EEPROM Record and Playback on Explorer 16
Ho yeh, I'm silly!LubinKerhuel wrote:Well, if you don't use it ?Ender wrote:Lubin what the utility to disable the SDO ?
Lubin
![Laughing :lol:](./images/smilies/icon_lol.gif)
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.
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.
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.
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.
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 1179 times
-
- SPI oscilloscope.zip
- (32.71 KiB) Downloaded 1124 times
-
- SPIwriteRead_v2.zip
- hex and .mdl file
- (13.51 KiB) Downloaded 1085 times
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
I changed commands to 8 bits--right
but also:
changed address to 8 bits :WRONG!
Stand By
John
Re: SPI EEPROM Record and Playback on Explorer 16
Still not working
Latest model attached.
john
![Sad :(](./images/smilies/icon_sad.gif)
Latest model attached.
john
- Attachments
-
- SPIwriteRead_v3.zip
- (14.02 KiB) Downloaded 1083 times
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
.
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...
![Cool 8)](./images/smilies/icon_cool.gif)
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...
Re: SPI EEPROM Record and Playback on Explorer 16
Lubin,
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.
![Idea :idea:](./images/smilies/icon_idea.gif)
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.
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.
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 1214 times
Re: SPI EEPROM Record and Playback on Explorer 16
![Very Happy :D](./images/smilies/icon_biggrin.gif)
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.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.
-
- 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
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
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
Re: SPI EEPROM Record and Playback on Explorer 16
Hi Lubin,
how to do it, I can easily find it.
Cheers,
John
That would be great. Then when I forgetLubinKerhuel wrote:place a link to this demo
![Confused :?](./images/smilies/icon_confused.gif)
Cheers,
John
Who is online
Users browsing this forum: No registered users and 6 guests