peu
- 16th January 2006, 19:03
Im lost in only six lines of code, I type this on microcode/pbp2.46 (yes I set 16F628A in microcode studio)
ADCON0 = 1
lectura var byte
mainloop:
Adcin 0, lectura
Goto mainloop
End
and I get errors during compile.
Its been a while from my last programming, so maybe Im missing something obvious here.
I would appreciate a working example of ADC for this pic or for 18f pics
Thanks in advance
mister_e
- 16th January 2006, 19:12
Yeah it's a bit obvious as there's no ADC in the 16F628... only analog comparator.
OUPS!
peu
- 16th January 2006, 19:15
Yeah it's a bit obvious as there's no ADC in the 16F628... only analog comparator.
OOPS!
Oops, so whats the correct code or example to read a potentiometer?
Thanks (that was fast)
rhino
- 16th January 2006, 19:33
You might look at the manual for the POT command. This is one option for measuring an analog signal without an ADC module. Another option is to use an external ADC or better yet, use a PIC with an ADC module on it. the 628 only has a comparator module.
peu
- 16th January 2006, 19:38
You might look at the manual for the POT command. This is one option for measuring an analog signal without an ADC module. Another option is to use an external ADC or better yet, use a PIC with an ADC module on it. the 628 only has a comparator module.
ok, I can use 18F6220, so this is the new code:
adcon0=1
lectura var byte
trisa=%00000111
lectura=0
mainloop:
Adcin 0, lectura
serout porta.3,6,[#lectura,"."]
Adcin 1, lectura
serout porta.3,6,[#lectura,"."]
Adcin 2, lectura
serout porta.3,6,[#lectura,"."]
serout porta.3,6,[10,13]
Goto mainloop
End
Im trying to read 3 potentiometers on ra0/1/2
I use serouts to know if I read something :)
[edit] this code is working I missed the # in the serout
now I want to use the read value to set HPWM
so I added this
DEFINE OSC 4
adcon0=1
Rval var byte
Gval var byte
Bval var byte
trisa=%00000111
mainloop:
Adcin 0, Rval
serout porta.3,2,[#Rval,"."]
Adcin 1, Gval
serout porta.3,2,[#Gval,"."]
Adcin 2, Bval
serout porta.3,2,[#Bval,"."]
serout porta.3,2,[10,13]
hpwm 3,Rval,300
hpwm 4,Gval,300
hpwm 5,Bval,300
Goto mainloop
End
no luck again :)
rhino
- 16th January 2006, 19:50
I can't even find a data sheet for 18F6220. Are you sure that is what you have. Also... there are TONS of examples here, and at MELabs website, and rentron.com on how to use the ADC module.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.