Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Using CAN/LIN Daughter Board On Explorer board 16

Status
Not open for further replies.

bubble_d

Junior Member level 3
Junior Member level 3
Joined
Sep 12, 2012
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,483
Hi everyone,

I am using the CAN/LIN AC164130-2 Board. My project involves the use of ADC and CAN interface.

for the time being I have been using the prototype board that comes with the board to work the adc portion.

Now that I have finished the ADC part, the next step is to switch the prototype board with the CAN/LIN board and use the pins on that.

Sounds easy enough, but when I switch the boards and use the corresponding pins on the Can board, the adc Doesnt work!

What am I doing wrong? Do I need to rename the pins I use or do I need to activate the board somehow? I am slightly confused...

This is the datasheet I am looking at: https://ww1.microchip.com/downloads/en/DeviceDoc/70319B.pdf

On page 19 it indicates which pins are what port.

Could it be that my board cant use the pins I need? (RB3,0,1,8)

Please help !
 

I am using the dspic33fj256gp710

Here is my Code:

main.c
Code:
#include <stdio.h>
#include <stdlib.h>
#include "p33FJ256GP710a.h"
#include "lcd.h"
#include "ADC.h"
#include "delay.h"

//ADC CHANNELS
// Each channel was selected such that a ground pin is right next to the input
// pin while the pin needed to be a ADC pin
#define Moduleinit 0x010A
#define B1ADC 3 //AN3 Selected for 'Battery Module' 1
#define B2ADC 0 //AN0 Selected for 'Battery Module' 2
#define B3ADC 1 //AN1 Selected for 'Battery Module' 3
#define B4ADC 8 //AN8 Selected for 'Battery Module' 4
#define multiplier 11
// Buttons
#define SW1 PORTDbits.RD6
#define SW2 PORTDbits.RD7
#define SW4 PORTDbits.RD13
//LEDS
#define LED1 LATAbits.LATA0
// I will start with A single battery module then once this
// works will I continue with all the modules.

//***************************************************************

_FOSC(OSCIOFNC_ON & FCKSM_CSDCMD & POSCMD_NONE);	//Oscillator Configuration
_FOSCSEL(FNOSC_FRC);								//Oscillator Selection
_FWDT(FWDTEN_OFF);									//Turn off WatchDog Timer
_FGS(GCP_OFF);										//Turn off code protect
_FPOR( FPWRT_PWR1 );								//Turn off power up timer

void Update_LCD( void );
double voltage1;
double voltage2;
double voltage3;
const char mytext[] = "hello";
const char mytext1[] = "EDP 2013";
const char mytext2[] = "shitz";
const char mytext3[] = "Holla";
const char mytext4[] = "fuck you";
char result [24];

int main(void)
{

	//Variables For Switches
	int	SW1Pressed=0;
	int	SW2Pressed=0;
	int	SW4Pressed=0;
	double v1 =0;
	double v2=0;
	double v3=0;

	TRISA = 0x007E;			//Make all PORTs all outputs
	/* Initialize LCD Display */
	Init_LCD();
	/* Welcome message */
	home_clr();
	puts_lcd( (char*) &mytext[0] );
	line_2();
	puts_lcd("BITCHES");
	
	initADC(Moduleinit);

	TRISB = Moduleinit; //Sets RB3/AN3 as input since AN3 is being used as analog Input
	

	while(1)
	{				// delay 200ms
	

		
		

		if(SW1Pressed==1){
		
		home_clr();
		
		v1 = readADC(B1ADC); //Read ADC
		voltage1 =(v1/1024)*3.3;
	
		

		sprintf(result,"Voltage 1 : %0.2f",voltage1);
		puts_lcd(&result);
		Delay(500);
}else if(SW2Pressed==1){

	home_clr();
		
		v2 = readADC(B4ADC); //Read ADC
		voltage2 = (v2/1024)*3.3;
	
		

		sprintf(result,"Voltage 2 : %0.2f",voltage2);
		puts_lcd(&result);
		Delay(500);

}else if(SW4Pressed==1){

	home_clr();
		
		v3 = readADC(B3ADC); //Read ADC
		voltage3 = (v3/1024)*3.3*multiplier;
	
		

		sprintf(result,"Voltage 3 : %0.2f",voltage3);
		puts_lcd(&result);
		Delay(500);

}

		if(!SW1){
		
		SW1Pressed=1;
		SW2Pressed=0;
		SW4Pressed=0;
		

		}else if (!SW2) {
		
			SW1Pressed=0;
			SW2Pressed=1;
			SW4Pressed=0;
		

		}else if (!SW4) {

			SW1Pressed=0;
			SW2Pressed=0;
			SW4Pressed=1;
		}

		
}
}

adc.h

Code:
#include "p33FJ256GP710a.h"


// Start with one pin being used to read a single battery
// Next read all four batteries from battery circuit.


// initialize the ADC for single conversion, select Analog input pins

//MODULE 2 ***********************************************************************************************************************************
void initADC( int amask)
{
    AD1PCFGH = amask;      // select analog input pins
    AD1CON1 = 0x00E8;     // data output format-integer, auto convert after end of sampling.12bit Operation mode. No need to include a delay loop to provide time for completion of sampling
    // Was 0x00e0 for singe channel

	AD1CSSL = 0;          // no scanning required
    AD1CON3 = 0x1FFF ;     // Use internal clock, max sample time avail is 31Tad, conversion time Tad = 128*Tcy = 128*(2/Fosc) = 256/8MHz = 32us which is > (required)75ns ); 31 Tad = 31*32us = 992us is the sample time. About 100samples/sec
    //Possibly 1FFFF Check Both
	AD1CON2 = 0x0300;          // use MUXA, AVss and AVdd are used as Vref+/-
	// Was 0x0000
    AD1CON1bits.ADON = 1; // turn on the ADC
} //initADC


int readADC(int channel)
{
	AD1CHS0bits.CH0SA = channel;			// Select the channel to convert
	IFS0bits.AD1IF = 0; 					// Clear ADC interrupt flag
	AD1CON1bits.DONE=0;						// Clear Done Flag
	AD1CON1bits.SAMP=1; 					// Start sampling 

	while(IFS0bits.AD1IF == 0);				// Wait for conversion complete

	AD1CON1bits.ASAM = 0; 					// Then stop sample/convert...
	return(ADC1BUF0);
}

I requested help earlier this month for my adc portion, here is the post : https://www.edaboard.com/threads/275705/
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top