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.

pic18f2550 motor problem.

Status
Not open for further replies.

mistrafantastic

Newbie level 4
Joined
Apr 30, 2012
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,323
hello everyone.

i am an computer engineering student in turkey. in our project class we need to make a blood pressure device with a group of fellow students.

so i designed a hardware, i wrote the code in simulation, everything is working. but in the board not a single volt in the pic's pins :) thereby i cannot trigger the motor. i've tried 4 different 2550's and so many codes.

i use ccs c compiler for codes, brenner 8 as a programmer and proteus 7 for schematic and pcb works.

zWnUh.png


Code:
/* 18f2550 header i */

#include <18F2550.h>

#device ADC=8

#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN

#use delay(clock=20000000)    /*16 Mhz*/




#use rs232(baud=9600, parity = N, xmit=PIN_C4, rcv=PIN_C5, bits = 8) /* TODO */

#include <usb_cdc.h>
#include <usb_desc_cdc.h>
#include <pic18_usb.h>


/* standart kutuphaneler */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/* port yonlendirme a,b,c portlari icin */
#use fast_io(a)
#use fast_io(c)
#use fast_io(b)

//define states for motor control
#define startState 0
#define inflate1State 1
#define inflate2State 2
#define deflateState 3
#define resetState 5

//define states for Measure control
#define Sys_Measure 6
#define Sys_Cal 7
#define Rate_Measure 8
#define dias_Measure 9 
#define dias_Cal 10   

static byte veriPaketi[8];

void initialize(void);

//declare functions for motor control            
void start_state(void);
void inflate1_state(void);
void inflate2_state(void);
void deflate_state(void);
void reset_state(void);

//declare all functions for measuring control
void pressuremeasure(void);
void sysmeasure(void);
void syscal(void);
void ratemeasure(void);
void diasmeasure(void); 
void diascal(void);

//declare variable for motor controls
unsigned char Maybe0,Maybe1,Maybe2;
unsigned int currentState;
unsigned int timepress0, timepress1, timepress2;

//declare variable for measuring and calculating value
float DC_gain;
unsigned char meas_state;
unsigned int timing, timerate, timerun_dias, timecount, timedeflate; 
float  maxpressure, pressure,accum_data, press_data; 
unsigned char count, stop_count;

//ADC data variables
float Vref;
float data; // amk
float adc_data, former;

byte alinan;

//define counter
unsigned char sys_count, count_average, countpulse;

//declare rate measure variable
float time_pulse, pulse_period, total_pulse_period, pulse_per_min;

//declare systolic and diastolic variable
float systolic, diastolic;

//declare all the threshold values
float TH_sys, TH_rate, TH_dias;

void main(void)
{
   char my[6] = "grup1";
   
   initialize();
   usb_init();
   usb_task();
   
   output_high(PIN_C6);
   delay_ms(1000);
   output_low(PIN_C5);
   
   //usb_wait_for_enumeration();
   
   
   
   if(usb_enumerated()) {
      disable_interrupts(GLOBAL);  
      
      printf(usb_cdc_putc ,"grup1");
      usb_put_packet(1, my, 6, USB_DTS_TOGGLE);
      
   }
   
   /*
   while ( usb_cdc_kbhit() ) {
      
      alinan = usb_cdc_getc();
      
     if(alinan == 'V' || alinan == 'v') break;
   }
   */
   while(1)
   {     
      output_toggle(PIN_C6);
      delay_ms(1000);
      
      
      switch(currentState)
      {        
      case startState:
         start_state();
         break;
      case inflate1State:
         inflate1_state();
         break;
      case inflate2State:
         inflate2_state();
         break;
      case deflateState:
         deflate_state();
         break;
      case resetState:
         reset_state();
         break;

      }
   }

}
//***********************************************
void start_state(void)
{   
   sys_count=0;
   pressure = 0;
   accum_data=0; 
   press_data=0; 
   count=0;
   stop_count=0; 
   maxpressure = 160; /* 180 */
   meas_state = Sys_Measure; 
   former=TH_sys-0.01;
   
   timerun_dias=0;
   time_pulse=0;
   timerate=0;
   
   timing=40;
   
   total_pulse_period=0;
   systolic=0;
   diastolic=0;
   pulse_per_min=0;
   
   sys_count=0;
   count_average=0;
   countpulse=0;
   
   /* TODO */
   currentState = inflate1State;
   Maybe0 = 0;
   timepress0 = 0;  
   timecount=0;
   //turn on motor and close the valve
   output_high(PIN_C6);
   output_low(PIN_C7);
      
   
}
//***********************************************

void inflate1_state(void)
{
   int8 intPressure;
   
   set_adc_channel(1);
   delay_ms(40);
   while(1){
      pressure = (read_adc()/5 - 0.04)/0.018;;
      if(pressure > 2,4) break;
   }
   
   {
      timecount=0;  
      intPressure = ((int) pressure);
      usb_cdc_putc((char) intPressure);
   }

   //turn off motor and open the valve
      output_high(PIN_C7);
      output_low(PIN_C6);
   
   {
      currentState = inflate2State;
   } 

}
//***********************************************
void inflate2_state(void)
{  
   int8 sis2;
   int8 dias2;
   float vOut;
   float sis;
   float dias;
      
   while(1){
      pressure = (read_adc()/5 - 0.04)/0.018;;
      if(pressure < 2,4) break;
   }
   
   // formül
   sis = pressure* 0.0075; // büyük tansiyon
   sis2 = ((int) sis); // büyük tansiyon
   usb_cdc_putc((char) sis2);
   
   // delay kücük tansiyon
      delay_ms(4000);
      set_adc_channel(1);
      pressure = (read_adc()/5 - 0.04)/0.018;
      dias =  pressure* 0.0075;
      dias2 = ((int) dias ); // kücük tansiyon
      usb_cdc_putc((char) dias2);
      
      currentState = deflateState;   
      timedeflate = 0;    
   
    

}
//***********************************************
void deflate_state(void)
{                                         
   int8 intPressure;
   {
      /* önce inte cast.
         int i byte ya da char 
         sonra gönder
      */
      intPressure = ((int) pressure);
      usb_cdc_putc((char) intPressure);
      //turn off motor and open the valve
      output_low(PIN_C6);
      output_high(PIN_C7);
      currentState = resetState;
      Maybe1 = 0;
      timepress1 = 0;                            
   }
   
   if(currentState==deflateState) pressuremeasure(); //if still deflating, measure everything
}

//***********************************************
void reset_state(void)
{   
                    
   if(!(input(PIN_B1)) && (timepress2 > 30)) Maybe2 = 1; /* dörttü üc oldu */
   if(Maybe2 && ((input(PIN_B1) == 0))) // TODO 1 de olabilir.
   {       
      currentState = startState;
      timepress2 = 0;
      Maybe2=0; 
   }

}
//***********************************************
// Function to measure everything
//------------------------------------------------
void pressuremeasure(void)
{
   switch (meas_state)
   {          
   case Sys_Measure:
      if(timing==0) sysmeasure(); //sampling signal at 40msec
      break;

   case Sys_Cal:
      if(timing==0) syscal();
      break;

   case Rate_Measure:
      if(timing==0) ratemeasure();
      break;

   case dias_Measure:
      diasmeasure();
      break;

   case dias_Cal:
      diascal();
      break;

   } //switch

}//pressuremeasure
//*********************************************************

void sysmeasure(void)
{
   if(timing==0)
   {
      set_adc_channel(0);
      data = read_adc();
      delay_ms(40); // adc okumasi icin süre veriliyor.

   //enable ADC and set prescaler to 1/128*16MHz=125,000
   //and set interupt enable
   //and start a conversion
   enable_interrupts(INT_TIMER0);

   } 
   if(sys_count>=6)
   { 
      meas_state = Sys_Cal;
      timecount=0;
   }

   if(timecount>=200)
   {  
      timecount=0;
   } 
}

//***********************************************************
//this function is to calculate systolic pressure
void syscal(void)
{

   set_adc_channel(0);
   data = read_adc();
   delay_ms(40); // adc okumasi icin süre veriliyor.
      //ADMUX = 0b00100000; //choose ADC0 for reading AC /*salihe sor TODO */

   //enable ADC and set prescaler to 1/128*16MHz=125,000
   //and set interupt enable
   //and start a conversion
   enable_interrupts(INT_TIMER0);

   if(timecount>=200)
   {  
      timecount=0;
   } 


}//syscal

//************************************************************
void ratemeasure(void)
{
   int8 intPulse;
   set_adc_channel(0);
   data = read_adc();
   delay_ms(40); // adc okumasi icin süre veriliyor.
   //ADMUX = 0b00100000; //choose ADC0 for reading AC /*salihe sor TODO */

   //enable ADC and set prescaler to 1/128*16MHz=125,000
   //and set interupt enable
   //and start a conversion
   enable_interrupts(INT_TIMER0);
   
   //calculate the mean of pulse rate
   if(count_average==5)
   {
      pulse_period = total_pulse_period/5000;
      pulse_per_min= 60/pulse_period;  

      /* TODO */
      intPulse = ((int) pulse_per_min);
      usb_cdc_putc((char) intPulse);
      meas_state = dias_Measure;
      //then set timerun_dias=0
      //also reset count_average for the next operation
      count_average=0;
      timerun_dias=0;
   }  
}
//************************************************************
void diasmeasure(void)
{
   set_adc_channel(0);
   data = read_adc();
   delay_ms(40); // adc okumasi icin süre veriliyor.
      //ADMUX = 0b00100000; //choose ADC0 for reading AC /*salihe sor TODO */

   //enable ADC and set prescaler to 1/128*16MHz=125,000
   //and set interupt enable
   //and start a conversion
   enable_interrupts(INT_TIMER0);

}//dias measure
//*************************************************************

void diascal(void)
{
   set_adc_channel(0);
   data = read_adc();
   delay_ms(40); // adc okumasi icin süre veriliyor.
      //ADMUX = 0b00100000; //choose ADC0 for reading AC /*salihe sor TODO */

   //enable ADC and set prescaler to 1/128*16MHz=125,000
   //and set interupt enable
   //and start a conversion
   enable_interrupts(INT_TIMER0);

   if(timecount>=200)
   { 
      timecount=0;
   } 

}

void initialize(void)   
{                       

   timecount=0;    
   timepress0 = 0;
   timepress1 = 0;     

   /* benim eklediklerim */
   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);

   set_adc_channel(0); /* AN0'dan okuma alinacak */
   set_adc_channel(1); /* AN1'den okuma alinacak */

   

   
   set_tris_c(0x06);  /* sikinti olabilir.  */
   set_tris_c(0x07);  /* sikinti olabilir.  */
   
   
   // buton bacaklari high a set edilecek.
   
   output_high(PIN_B3);
   output_high(PIN_B2);
   output_high(PIN_B1);
   
   // motor and valve controls
   
   output_low(PIN_C6); // motor
   output_low(PIN_C7); // valve
      
   /* timer interrupts ali. */
   
   enable_interrupts(GLOBAL); 
   
   enable_interrupts(INT_TIMER0); 
   setup_timer_0(RTCC_EXT_H_TO_L | RTCC_DIV_256 | RTCC_8_BIT);
   
   enable_interrupts(INT_TIMER1); 
   setup_timer_1(RTCC_EXT_H_TO_L | RTCC_DIV_256 | RTCC_8_BIT);
   set_timer0(0);
   set_timer1(1);
   
   TH_sys= 4.0;
   TH_rate = 2.5;
   TH_dias = 4.8;
   timerun_dias=0;
   time_pulse=0;
   timerate=0;
   
   maxpressure = 160; /* 180 */ 
   meas_state = Sys_Measure; 
   former=TH_sys-0.01;

   timing=40;

   total_pulse_period=0;
   systolic=0;
   diastolic=0;
   pulse_per_min=0;
   Vref=5.0;          

   sys_count=0;
   count_average=0;
   countpulse=0;

   DC_gain=213;
   
   accum_data=0; 
   press_data=0; 
   count=0;
   
   currentState = startState;
}
 

you schematic is not clear..mail me your schematic..i make you sure will put away your each and every doubt.

---------- Post added at 09:11 ---------- Previous post was at 08:49 ----------

i think your schematic is perfect..have you check the voltage at Vcc pin ang groud??is it alright???
 

you schematic is not clear..mail me your schematic..i make you sure will put away your each and every doubt.

---------- Post added at 09:11 ---------- Previous post was at 08:49 ----------

i think your schematic is perfect..have you check the voltage at Vcc pin ang groud??is it alright???

yes i ve checked several times, its allright. but the pins is not work fine. i use c6 pin for motor, i didnt see the 5v on c6 pin for example. and i've tried other pins.

thanks in advance.
 

is it providing 5 volts at other pins???or not providing any thing at all??
 

is ths ucontroller have reset ciruitry..???because i could'nt see in schematic..or it has any thing else in replacement for reset
 

check in data sheet may be it require pull up at its pins???
 

i checked that. in 2550 c6 and c7 pins does not require pull-ups.
 

check your reset circuit also..check in data sheet that it reset on high or low pulse??some time this is the only problem that the controller is not working..if it reset at high pulse then check without pressing button what is going to your reset pin??is it 0??yes??then its allright??otherwise correct it??

---------- Post added at 09:34 ---------- Previous post was at 09:33 ----------

and how much the current pin can provide??
 

i ve checked it it and my electrinocial teacher checked it just you say. there's no problem in it. IS Crystal causes this kind of problem?
 

no crystal does'nt???ummmmmmm what you should do now??can you send me the picture of your hardware??layout too??want to have close look??
 

try to make a simple circuit at your breadboard..check the programm of flashing led ..if this work..then debug your origional PCB.accordingly
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top