Page 1 of 1
Reducing scope of ADC byte in code 0-255 to 50-100
Posted: Wed Aug 22, 2012 5:02 am
by Chet
Hello to my fellow Flowcode fanatics. I'm trying to figure out a way to reduce the "scope" or in other words locate the "sweet spot" of a ADC byte in Flowcode 5. I have a simple pulse generator that uses a timer interrupt to toggle a pin. At the moment the pulse on off values are 0-255 ms but I need to shrink that to between say 50-100ms while keeping the full rotation of the 10k pot usable. In other words I can't truncate the upper and lower voltages (that would be cheating)

. My PCB for this project leaves no room for adding trim resistors to the ADC so I need to do this in code. I can post my code if needed but hope this simple issue won't require it. I appreciate any feedback, thank you.
Re: Reducing scope of ADC byte in code 0-255 to 50-100
Posted: Wed Aug 22, 2012 9:50 am
by Benj
Hello Chet,
What about sampling the ADC to collect the byte reading 0 - 255. Then divide this reading by 5 to give you 0 - 51. Finally add 50 to the reading and this will give you 50 - 101. Is this any good?
Re: Reducing scope of ADC byte in code 0-255 to 50-100
Posted: Wed Aug 22, 2012 9:51 am
by Enamul
Hi,
This can be work around this way..
For example, ADC =0 to 255.
In the calculation box you can put the following immediately after ADC read..
so, for ADC = 0, new ADC will be ((50*0)/255)+50 = 50
and for ADC = 50, new ADC will be ((50*50)/255)+50 = 9+50 = 59
and for ADC=255, new ADC will be ((255*50)/255)+50 = 50+50 =100
Re: Reducing scope of ADC byte in code 0-255 to 50-100
Posted: Wed Aug 22, 2012 10:57 am
by Benj
Hi Enamul,
To get your calculations to work you may need to assign ADC as an INT variable rather then a Byte. Not 100% on this but 255 * 50 worries me using byte variables

Re: Reducing scope of ADC byte in code 0-255 to 50-100
Posted: Wed Aug 22, 2012 11:09 am
by Enamul
Hi Ben,
Like you I was thinking the same but I tested that in Real PIC before posting which shows fine. I have just now tested in ECIO-40 works fine even with ADC is byte.

Edit: I have looked through the assembly generated by Boostc. It's due to the intermediate registers used in multiplication and division are 2 locations not Byte..
Code: Select all
__div_16_1_00003_arg_a EQU 0x0000002E ; bytes:2
__div_16_1_00003_arg_b EQU 0x00000030 ; bytes:2
Code: Select all
MOVWF gbl_FCV_ADC
MOVF gbl_FCV_ADC, W
MULLW 0x32
MOVF PRODL, W
MOVWF __div_16_1_00003_arg_a
MOVF PRODH, W
MOVWF __div_16_1_00003_arg_a+D'1'
MOVLW 0xFF
MOVWF __div_16_1_00003_arg_b
CLRF __div_16_1_00003_arg_b+D'1'
CALL __div_16_1_00003
MOVF CompTempVarRet178, W
MOVWF gbl_FCV_ADC
MOVF CompTempVarRet178+D'1', W
MOVWF CompTempVar2252
MOVLW 0x32
ADDWF gbl_FCV_ADC, F
Re: Reducing scope of ADC byte in code 0-255 to 50-100
Posted: Wed Aug 22, 2012 12:36 pm
by Chet
Thank you all, I'm using a 12F683 so I think this will work even if I have to use int, I'll tweak my code and let you know how it goes when I get a spare moment. Cheers
Re: Reducing scope of ADC byte in code 0-255 to 50-100
Posted: Thu Aug 23, 2012 3:16 am
by Chet
Enamul, as far as I can tell without running this in hardware your math works perfect. Thank you again, it took less than 5 minutes to edit my flow cart.

Re: Reducing scope of ADC byte in code 0-255 to 50-100
Posted: Thu Aug 23, 2012 8:44 am
by Enamul
Glad to know that you can use it
