|
|
View previous topic :: View next topic |
Author |
Message |
imatos2
Joined: 03 Mar 2024 Posts: 3 Location: brazil
|
18F67K22 - HELP SIMPLE ADC NOT WORKING |
Posted: Sun Mar 03, 2024 2:55 pm |
|
|
Hi.
This is the first time I try to use this chip. 18F67k22.
Im using CCS 5.070. I can setup ADC converter for other chips but never for this one. Even the Wizard cant. I only want to make one Channel read 0~5vts and send to portB. But there must be something that is not correct or the version of CCs is not ok. Can anyone PLEASE !! HELP ME before I get crazy !! Thanks in advance. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sun Mar 03, 2024 4:30 pm |
|
|
Please post your code ! A small test program will do. |
|
|
imatos2
Joined: 03 Mar 2024 Posts: 3 Location: brazil
|
|
Posted: Sun Mar 03, 2024 7:58 pm |
|
|
ADC works but the LED on RD1 was supposed to flash every 200ms but i tryied without success.
thanks
#include "18F67K22.h"
#fuses HSM,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOCPD,BORV18,NODEBUG,NOCPB,STVREN,NOPLLEN,NOFCMEN,SOSC_DIG
#device ADC=12
#BYTE PORTA = 0x0F80
#BYTE PORTB = 0x0F81
#BYTE PORTC = 0x0F82
#BYTE PORTD = 0x0F83
#BYTE PORTE = 0x0F84
#BYTE PORTF = 0x0F85
#BYTE PORTG = 0x0F86
#use delay(clock=16000000)
#define led pin_D1
void main() {
int16 mm;
set_tris_a(0X01);
set_tris_b(0x00);
set_tris_c(0x00);
set_tris_d(0x00);
set_tris_e(0x00);
set_tris_e(0x00);
set_tris_f(0x00);
PORTA = (0x00);
PORTB = (0x00);
PORTC = (0x00);
PORTD = (0x00);
PORTE = (0x00);
PORTF = (0x00);
PORTG = (0x00);
setup_oscillator(OSC_PLL_ON);
SETUP_ADC_PORTS(sAN0||VSS_VDD);
setup_adc (ADC_CLOCK_DIV_16|ADC_TAD_MUL_20);
set_adc_channel(0);
delay_ms(30);
while(true) {
mm=read_adc();
delay_ms(100);
output_b(mm);
if (mm>=300)
{
output_bit(LED,1);
delay_ms(200);
output_bit(LED,0);
delay_ms(200);
}}} |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Mar 04, 2024 2:31 am |
|
|
First thing. Learn to use the code buttons!....
Now, what happens???. Tell us what you get?.
The 67K22 is a 'fussy' chip on it's power supply. It will not wake up
correctly is the rise time of the power supply is too slow. Have you tested
with a simple 'flash an LED' program to verify the chip actually is starting?.
Then second comment. You should always have PUT enabled with a crystal.
Now I'd definately re-think how you code your setup. I think you are
trying to run a 4MHz crystal, and clock at 16Mhz with the PLL from this?.
If so, setup as:
Code: |
#include "18F67K22.h"
#device ADC=12
#use delay(CRYSTAL=4MHz, CLOCK=16MHz)
#fuses HSM, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOCPD, BORV18
#fuses NODEBUG, NOCPB, STVREN, NOFCMEN, SOSC_DIG, NOXINST
//PUT should always be used when using a crystal.
//Explicitly setting HSM to handle chip erratum.
|
Makes it much more obvious what the clock actually is.
Now there is an obvious issue with your 'output_b(mm)'. I'd suggest
dividing by 16 for this.
Now do you have Avss and Avdd connected?. These are required.
Look carefully at this line:
SETUP_ADC_PORTS(sAN0||VSS_VDD);
There is a typo here.....
Your compiler is late enough, that this should work. So as I say, tell
us what you are actually seeing?. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Mon Mar 04, 2024 4:27 am |
|
|
As Mr. Ttelmah said, you are trying to show a 16 bit variable on an 8 bit port, so divide mm by 16 before sending it to PORTB. Connect AVDD and AVCC or ADC won't work, Third, you have a 100ms delay after each reading so LED isn't going to blink 200ms on, 200ms off. Just delete that row. |
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Mon Mar 04, 2024 12:45 pm |
|
|
Are you powering the microcontroller with 5V? _________________ Electric Blue |
|
|
imatos2
Joined: 03 Mar 2024 Posts: 3 Location: brazil
|
|
Posted: Mon Mar 04, 2024 4:06 pm |
|
|
Yes I am applying 5v to the Chip, To AVDD, AVSS
ADC works fine.
Just didn't know how to fix the oscillating frequency.
Thanks |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|