# PIC10F220 RC filter first order by numerical simulation in the microcontroller

1. ## PIC10F220 RC filter first order by numerical simulation in the microcontroller

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):

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

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

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

Thanks

•

2. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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.

3. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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

4. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

I can write PIC asm code for you but you have to give me the C source code or algorithm for your work.

5. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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.

6. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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

7. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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.

•

8. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

yes i talk about using SPI LCD to display data, i want SPI LCD (CAN_USB_LCD ) USB

9. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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.

10. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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.

•

11. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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

12. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

No, I meant which SPI chip is driving the SPI LCD. Check the chip on the SPI LCD. Is the LCD HD44780 Compatible ?

13. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

yes it is the LCD HD44780 compatible (HD44780 1602 LCD Module )

14. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

Why you always give part of answer. I asked which SPI port expander are you using to drive LCD ?

15. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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.

16. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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

17. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

Provide the datasheet of the LCD.

18. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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

•

19. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

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.

20. ## Re: PIC10F220 RC filter first order by numerical simulation in the microcontroller

-(SCL) is the clock signal
-(SI) ist the data signal
- (CSB) activation signal
so a standard SPI I meant
and Sorry for the misunderstanding

--[[ ]]--