PDA

View Full Version : Most memory saving way for comparing 98 preset values with ADC input?



CuriousOne
- 2nd August 2018, 04:52
Hello.

Have to run a code in 12F1840, so quite limited in memory.

What I have. There are 98 preset values, pre-defined at programming stage, will not change, ranging from 0 to 100. The code should measure ADC input, convert it to 0-100 range value, and generate HPWM with duty cycle according to one defined in table. Say ADC reading is 20, then data is read from 20th cell of table, and data is 45 in that table. And so on. PBP allows several ways to do this, like multiple if-then, arrays, etc. Which one will be most memory efficient?

mpgmike
- 2nd August 2018, 11:51
On page 13 of the PIC12F1840 Data sheet, Section 3.1.1.1, the RETLW ASM command is explained. It's used on the following page as well. Finally, on page 299 the Instruction RETLW is covered.

CuriousOne
- 2nd August 2018, 15:04
Is this ASM discussion forum?

towlerg
- 3rd August 2018, 14:43
Try coding it as a huge SELECT statement, you might be surprised how little memory it uses.

Mike, K8LH
- 9th August 2018, 00:08
Gentlemen... Does PBP provide a way to access Special Function Registers, like FSR0L, FSR0H, INDF0, etc., directly?

richard
- 9th August 2018, 00:46
Does PBP provide a way to access Special Function Registers, like FSR0L, FSR0H, INDF0, etc., directly?

yes there are a number of ways
my favourite is

timer0 var byte ext
@timer0 = TMR0

OR even

myFSR var word ext
@myFSR= FSR0L

or inline asm

@ FSR0L=22


OR USING PBP MACRO

PBPBYTE VAR BYTE
PBPWORD VAR WORD

@ MOVE?BB _PBPBYTE,FSR0L
@ MOVE?WW _PBPWORD,FSROL

richard
- 9th August 2018, 13:29
surprised no one pulled me up on this


or inline asm

@ FSR0L=22


should be

or inline asm

or just

FSR0L=22