Continue to Site

Welcome to EDAboard.com

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

How many steps can a PIC program have?

Status
Not open for further replies.

JohnJohn20

Advanced Member level 4
Full Member level 1
Joined
Feb 2, 2012
Messages
111
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,377
Hi. I wish to use the ADC capability of a PIC16F88 chip to measure voltage across a thermistor.

Because the thermistor voltage/temperature curve is not linier, I think I will have to compare the measurement (a 10 bit number) with up to 100 known values (if I want 1 degree C accuracy) like this: (I am sure there are more efficient ways but for the sake of argument.....)

If X > 100 Then Temp = 100
Else If X > 99 Then Temp = 99
Else If X > 98 Then Temp = 98
Else If X > 97 Then Temp = 97
Else If X > 96 Then Temp = 96
Else If X > 95 Then Temp = 95

etc. But this makes the program large. The PIC16F88 datasheet says that the Program memory has:
- Flash 7168 bytes and
- the # Single-word Instructions = 4096.

So how many instruction lines can I put in a program?

For example, how much memory space do these instructions use (or, how many instruction words are each of these steps)?

movlw 0xFE ; 11111110
movwf TRISA

bcf STATUS, RP1 ;

movlw 0x01 ;
movwf PORTA

btfsc PORTA,3
call Delay1
call Delay2

Thanks.
 
Last edited:

The data sheet explains everything. All PIC assembly instructions use one address but if you write in a high level language the numnber of PIC instructions taken to perform each language function is decided by the compiler and will vary from one to another, even if the exact same code is compiled. The first block of code you wrote is in a high level language and could use hundreds of bytes, the second is in assembler and has 8 lines so it uses 8 addresses.

It should be feasible to add a correction factor to 'straighten' the non-linearity in a much simpler way. It depends on the characteristics of your thermistor of course but you could possibly calculate a correction factor in less code than 100 compare instructions.

Brian.
 
Hi,

A common way to convert a ntc adc reading is to use a large lookup table, but be careful you do not go over a 256 byte boundary.
An example, though not the simplest, is attached.

If you search there are some much simpler algorithms around to save using long lookup tables.

You can always see how much space your code is using by Viewing the Disassembly Listing or the Memory Usage Gauge in MPlab
 

Attachments

  • temp1.zip
    7.9 KB · Views: 133
the second (code block) is in assembler and has 8 lines so it uses 8 addresses.

Thank you Brian. Just to make clear. Is each line of assembler code one instruction-word? (Of which the 16F88 can hold 4096).

Chris.
 

Yes, that is correct. Note that all except the top of the range PICs use Harvard architecture which means the program memory is not shared with RAM or EEPROM although you can store constants in it. So as well as 4096 instructions you can also have up to 368 bytes of RAM and 256 bytes of EEPROM.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top