Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

PIC10F220 RC filter first order by numerical simulation in the microcontroller

Status
Not open for further replies.

thierryneuch

Member level 2
Joined
Jun 7, 2015
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
313
I want to make an electronic device that Measures the wind speed in Beaufort. The definition of the Beaufort scale requires the calculation of an average over a period of 10 minutes. We choose to do this using the following principle (average with forgetfulness): filtre-passe-bas2.gif

For economical and space reasons, we choose to realize the RC filter by numerical simulation in the microcontroller.
Power supply: 3V analog output voltage proportional to the Beaufort scale with 0 corresponding to 0V Beaufort, 3V corresponding to 9 Beaufort (it will not show values above 9 Beaufort)
Interface to the LCD module: SPI (SPIdatas and SPI clk) Wind speed encoded in 8 bits

:bang: I expected to find some help here because I have almost no idea how to program in assembly language.
I have difficulties and problems understanding the management and integration of SPI communication and problems And difficulty as the exact conversion speed => Beaufort and how to use it, and to make a sliding average

:bang: The code is highly optimized That's why I come to ask your help :fs: and knowledge. Any ideas is welcome!

Thanks
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,372
Helped
4,727
Reputation
9,469
Reaction score
4,496
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,634
That's an interesting challenge. It should be possible, the limitation is only having 16 bytes of RAM, some of which will be needed to hold the running average.

Questions:
1. You want the average over 10 minutes to be shown but how frequently do you want the reading to be taken?
2. Is a simple (last reading + new reading)/2 average good enough?
3. most SPI interfaces need data, clock and an enable signal, can you confirm that. You didn't mention the enable signal.
4. is the 3V supply stabilized? The ADC reading the analog voltage will lose accuracy if the supply changes.

Brian.
 

thierryneuch

Member level 2
Joined
Jun 7, 2015
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
313
clock and an enable signal
yes a simple (last reading + new reading)/2 average good enough and the 3V supply is stabilized
frequency of reading It doesn't greatly matter
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
I can write PIC asm code for you but you have to give me the C source code or algorithm for your work.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,372
Helped
4,727
Reputation
9,469
Reaction score
4,496
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,634
I think they did.
Take readings say once a second (wind speed is relatively slow to change so no need to do it faster).
Add the reading to the previous one and halve the result so you get a running average.
Every 10 seconds send the speed scaled 0 - 9 to the LCD.

It is possible to store and average several readings but with only 16 bytes of RAM and some of that needed for the SPI software it would be hard to code.

Brian.
 

thierryneuch

Member level 2
Joined
Jun 7, 2015
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
313
I can for example change the microcontrollerand take the PIC12F1840
But I'm still a beginner in assembler programming I have not much idea about how to program with (SPI communication, exact conversion speed => Beaufort and how to use it, and to make a sliding average)
I have assimilated the course of signal processing with passive RC filter but unfortunately I do not know how to program in assembler My knowledge is limited
And I do not have the C source code or algorithm only what I wrote at the beginning
:bang:
That's why I come to ask your help.Can anyone help me please.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
What do you mean by SPI. All I understood from your 1st post is that you want to interface a RC filter to ADC pin of PIC and take readings for 10 minutes. Why is SPI needed ? Are you talking about using SPI LCD to display data ? If yes, can you go for I2C LCD ?

I can write the code for PIC12F1840 in asm but with I2C LCD. I2C LCD needs 2 pins. If you still want SPI LCD then you have to mention what device you are using like Port expander for driving the LCD.
 

thierryneuch

Member level 2
Joined
Jun 7, 2015
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
313
yes i talk about using SPI LCD to display data, i want SPI LCD (CAN_USB_LCD ) USB
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,494
Helped
14,051
Reputation
28,357
Reaction score
12,709
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,187
An average over a 10-minute periode isn't calculated by a first order low-pass filter. Instead you'll sum the individual readings and divide by the number of readings.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
I have not written code for SPI LCD. Tell me what SPI chip you use to interface with LCD. I will see if I can write a code for it.
 

thierryneuch

Member level 2
Joined
Jun 7, 2015
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
313
I'm supposed to use normally the PIC10220 but This is quite complex .I can change it and taking PIC12F1840 chip so one of the two
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
No, I meant which SPI chip is driving the SPI LCD. Check the chip on the SPI LCD. Is the LCD HD44780 Compatible ?
 

thierryneuch

Member level 2
Joined
Jun 7, 2015
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
313
yes it is the LCD HD44780 compatible (HD44780 1602 LCD Module )
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Why you always give part of answer. I asked which SPI port expander are you using to drive LCD ?
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,372
Helped
4,727
Reputation
9,469
Reaction score
4,496
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,634
Thierry, what is being asked is how the LCD connects to the PIC. SPI needs an enable signal, a clock signal and a data signal. The "1602" with it's HD44780 needs 4-bit (or 8-bit) parallel data, an enable signal, a register select signal and optionaly a read/write signal as well. That's obviously too many signals to pass through a PIC with only 4 external connections. So your requirements are conflicting unless you use an external SPI to parallel converter or "expander".

I think a PIC 10F220 can do it if the interface is one analog voltage in and three SPI outputs but it's doubtful there is enough RAM to store say 10 readings then average them. It might be possible but would would take careful coding, especially as the result would involve a 16-bit product term If you change to a 12F1822 or 12F1840 type of PIC you have far more resources and can easily use 'C' as the programming language if you find assembly language difficult. They still only have 8-pins so the problem of interfacing to the LCD is still there. If you want to use the HD44780 without an additional port expander the cheapest and simples option is to move to a PIC with sufficient ports. My preference would be one of the 16F series with an on-board ADC.

Brian.
 

thierryneuch

Member level 2
Joined
Jun 7, 2015
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
313
this is the standard SPI with a line for the clk and a line for datas (so two IO). it is a LCD controlled by SPI. I just have to generate only an SPI DATA_OUT and confirm(validated) with SPI clk
 

thierryneuch

Member level 2
Joined
Jun 7, 2015
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
313
Excuse me sometimes I do not quite understand the question given my inexperience and my gap in the field

all what I know is SPI software must to create with GP1 and GP2 pin (pic10f220) and the LCD I must use the pin D5,D6,D7
the system has created is not yet ascended we will do it later That why I am open to suggestion
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,372
Helped
4,727
Reputation
9,469
Reaction score
4,496
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,634
SPI needs one extra signal, the 'enable'. You are correct that the clock signal tells the SPI receiver when the data line can be sampled but without the extra enable signal it cannot tell when the data starts and ends. The enable 'frames' the data so it picks the first bit first and so on, without it, there would be no way to tell which data bit was being sent at any time.

You have to use GP0 or GP1 as the analog inputs, those are the only two pins on the 10F220 that can be routed to the ADC. I would suggest using GP0 as the analog input and GP1, GP2 and GP3 to create the SPI interface.

Brian.
 

thierryneuch

Member level 2
Joined
Jun 7, 2015
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
313
SPI.png -(SCL) is the clock signal
-(SI) ist the data signal
- (CSB) activation signal
so a standard SPI I meant
and Sorry for the misunderstanding
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top