CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F67K22 - HELP SIMPLE ADC NOT WORKING

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
imatos2



Joined: 03 Mar 2024
Posts: 3
Location: brazil

View user's profile Send private message

18F67K22 - HELP SIMPLE ADC NOT WORKING
PostPosted: Sun Mar 03, 2024 2:55 pm     Reply with quote

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: 9120
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 03, 2024 4:30 pm     Reply with quote

Please post your code ! A small test program will do.
imatos2



Joined: 03 Mar 2024
Posts: 3
Location: brazil

View user's profile Send private message

PostPosted: Sun Mar 03, 2024 7:58 pm     Reply with quote

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: 19238

View user's profile Send private message

PostPosted: Mon Mar 04, 2024 2:31 am     Reply with quote

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: 456
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Mar 04, 2024 4:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 04, 2024 12:45 pm     Reply with quote

Are you powering the microcontroller with 5V?
_________________
Electric Blue
imatos2



Joined: 03 Mar 2024
Posts: 3
Location: brazil

View user's profile Send private message

PostPosted: Mon Mar 04, 2024 4:06 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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