Adc is stopping the main loop

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
be80be
Registered User
Registered User
Posts: 90
Joined: Mon Feb 23, 2009 2:15 am
Location: tn

Adc is stopping the main loop

Post by be80be » Fri Aug 21, 2015 1:17 am

Ok I never had a problem till now I don't think the problem is windows 10 I'm using a 18f2550 if I send code to LCD it works
but if I send adc data the loop stops at this.

Code: Select all

LCD.Write("DC Volts = ", DecToStr(ADVal / 100), ".", DecToStr(ADVal, 2), " ")
I have a led on portb it works fine up till you get to that part of code. I tried led blink on portb.0 to test osc it's working fine. but no go with sending adc data out the LCD

Here's whole code

Code: Select all

{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 8/20/2015                                                      *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18F2550
Clock = 20 
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.1
#option LCD_EN = PORTB.2

// uses LCD and AD libraries...
Include "LCD.bas"
Include "utils.bas" 
Include "ADC.bas"
Include "convert.bas"
          
// read the AD port and scale for 0 - 5 volts...
Function ADInAsVolt() As Word
   result = (ADC.Read(0) + 1) * 500 / 1024
End Function
Dim ADVal As Word
// sampled AD value...


// initialise and clear LCD...
       // PORTE as digital (LCD)
ADCON1 = %00001110
TRISA.0 = 1        // configure AN0 as an input 
TRISB.0 = 0

DelayMS (500)
LCD.Cls
DelayMS (500)
LCD.MoveCursor (1,1)
LCD.Write ("alive")
// main program loop...
//portb.0 =1
While true
   ADVal = ADInAsVolt
 //  portb.0 =1
   DelayMS (250)
  LCD.MoveCursor (2,1)
 //  portb.0 =1
   LCD.Write("DC Volts = ", DecToStr(ADVal / 100), ".", DecToStr(ADVal, 2), " ") // stops here
   PORTB.0 =1
   DelayMS(250)
   
   DelayMS (250)
   PORTB.0 = 0
   DelayMS (250)
Wend

be80be
Registered User
Registered User
Posts: 90
Joined: Mon Feb 23, 2009 2:15 am
Location: tn

Re: Adc is stopping the main loop

Post by be80be » Fri Aug 21, 2015 3:18 am

I looked at the files there is something wrong with the ADC.bas it's not setting the adc setting of the 18f2550
I have swordfish ver 2.2.2.5 I don't see any thing in the sys library that set a 18f2550 up.

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Adc is stopping the main loop

Post by Jerry Messina » Fri Aug 21, 2015 10:01 am

It seems ADC.bas is always a problem. There are so many different ADC modules it's hard to deal with.

Try this -
In ADC.bas, change the line

Code: Select all

#elseif _adc > 8
to

Code: Select all

#elseif _device in (18F2550, 18F4550) or (_adc > 8)
That should fix it for the time being.

Now, in your main program you should be able to use 'ADC.SetConfig(%00001110)' in place of 'ADCON1 = %00001110'
With any luck, ADC.Read should now work.

be80be
Registered User
Registered User
Posts: 90
Joined: Mon Feb 23, 2009 2:15 am
Location: tn

Re: Adc is stopping the main loop

Post by be80be » Fri Aug 21, 2015 2:58 pm

Thanks Jerry that fixed it.. It was getting lost in the ADC.bas
What made it bad is it wouldn't even let me set it in code because I was using the ADC.bas

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Adc is stopping the main loop

Post by Jerry Messina » Fri Aug 21, 2015 3:40 pm

Great, Burt.

Let me know if you have any luck with the oversampling routine. I didn't really test it very much.

be80be
Registered User
Registered User
Posts: 90
Joined: Mon Feb 23, 2009 2:15 am
Location: tn

Re: Adc is stopping the main loop

Post by be80be » Fri Aug 21, 2015 4:34 pm

I'm going to try it today, Hope I don't have to rewrite all my code I think I deleted it when I couldn't get the adc to read guess im the only one still using old 18f2550 but I have a bunch of them LOL I got them cheap 5 years ago I ordered 10 tubes I think it was like 250 0f them in all.

Post Reply