polilies
Joined: 24 Dec 2009 Posts: 1
|
adding onewire read func stops modbus |
Posted: Mon Jun 09, 2014 9:32 am |
|
|
compiler version 4.084
Hi !
i'm working on a project that has two PWM out and two ds18B20 temp sensor m and modbus communication . I use 16F877A as micro. one pwm is using pwm module and one is soft pwm. soft pwm uses ccp compare interrupt with timer1. And i use modbus protocol to set separate pwm frequency, duty cycles and read ds18B20 temp values.
But there is a problem with reading ds18B20 temp value and modbus communication. With ds18B20 read command pic doesn't answer any of my modbus query. Without ds18B20 read commands it's all fine. Even device response my queries every 50ms. it's prety perfect for me. (for one register query) i'm adding my code and i'm sorry if it's too confused.
Code: | //#define USE_WITH_PC 1
#include <16f877a.h>
#device *=16
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock=4M)
//#use fast_io(D)
//#use fast_io(A)
//#use fast_io(C)
#define MODBUS_TYPE MODBUS_TYPE_SLAVE
#define MODBUS_SERIAL_RX_BUFFER_SIZE 64
#define MODBUS_SERIAL_BAUD 19200
#define MODBUS_SERIAL_ENABLE_PIN PIN_D1
#define MODBUS_SERIAL_RX_ENABLE PIN_D0
#define MODBUS_ADDRESS 23
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
#define ONE_WIRE_PIN PIN_B2
#define LCD_POWER PIN_D7
#include <math.h>
#include "1wire.c"
#include "ds1820.c"
#include "Flex_LCD.c"
int1 Ton = 1;
int i = 0;
unsigned int16 pr2 = 254,event_count = 0,pwm_freq_iter = 0,pwm_freq_reminder = 0,duty2_reminder = 0;
unsigned int8 prescalex = 1,dutyx[]= {0,0,0,0};
int8 coils = 0b00000101;
int8 inputs = 0b00001001;
unsigned int16 hold_regs[] = {25600,25600,65280,0x5500,0x4400,0x3300,0x2200,0x1100};
unsigned int16 input_regs[] = {0x1100,0x2200,0x3300,0x4400,0x5500,0x6600,0x7700,0x8800};
unsigned int16 freq_old = 255,maxduty = 0,freq = 255,freq2 = 255,freq2_old = 255;
unsigned int16 exc_input[] = {0x1100,0x2200,0x3300,0x4400,0x5500,0x6600,0x7700,0x8800},exc_hold[] = {100,100,255,0x5500,0x4400,0x3300,0x2200,0x1100};
unsigned int8 address = 0,prescale[] = {1,4,16},prescaler[] = {4,5,6},rate = 100,rate2 = 100,rateold = 100,rate2old = 100,temp[] ={0,0,0,0};//,value1 =0,value2 =0,value3 =0;//index=0;//duty_h=0,duty_l=0,duty2_h=0,duty2_l=0,value0 =0,value1 =0,value2 =0,value3 =0,;
unsigned long duty = 0,duty2 = 0;
#include "C:\deneme Programlar\Modbus_pwm_softpwm_ds18B20_v1.0\modbus.c"
#include "C:\deneme Programlar\Modbus_pwm_softpwm_ds18B20_v1.0\pwm.c"
#include "C:\deneme Programlar\Modbus_pwm_softpwm_ds18B20_v1.0\eeprom_startup.c"
#include "C:\deneme Programlar\Modbus_pwm_softpwm_ds18B20_v1.0\ds1820.c"
/*
#int_ext
void ext_kesmesi()
{
for(i=0;i<3;i++){
write_eeprom(i,dutyx[i]);
delay_us(20);}
write_eeprom(4,make8(pr2,0));
delay_us(20);
write_eeprom(5,prescalex);
delay_us(20);
}
*/
#INT_CCP2
void compare_isr()
{
if(Ton){//get_timer1()<pwm_freq_iter){
Ton = 0;
ccp_2 = pwm_freq_iter - duty2;
output_low(pin_C1);
}
else{
Ton = 1;
ccp_2 = duty2;
output_high(pin_C1);//pinout up buzzer
}
set_timer1(0);
}
void main()
{
unsigned int16 *index,ds_counter = 0;
unsigned int32 value32;
signed int16 temp1 = 0, temp2 = 0;
float value = 5.0;
set_tris_c(0b10110000);
//port_b_pullups(TRUE);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
set_timer0(248); //modbus timer
modbus_init();
setup_ccp1(CCP_PWM); // Interrupt on compare mode // RC2 buzzer
setup_ccp2(CCP_COMPARE_INT ); // RC1
//ext_int_edge(H_TO_L);
//enable_interrupts(INT_EXT);
enable_interrupts(INT_CCP2); // Enable interrupt CCP1
enable_interrupts(GLOBAL);
///////////////eeprom//////////////
//eeprom_startup();
//set_timer1(0);
//ccp_2 = duty2;
//index = &value;
///////////////lcd/////////////////
//output_high(LCD_POWER); // Turn on power to LCD
//output_low(LCD_RW); // Set R/W pin on LCD to a low level
//lcd_init(); // Initialize the LCD
//lcd_putc("\fHello World\n");
//lcd_putc("Line Number 2");
/////////////lcd/////////////////
/*
// Modbus Adresi dip switch ile belirleme noktası
if(INPUT(PIN_D2)){
BIT_SET(address,0);
}
if(INPUT(PIN_D3)){
BIT_SET(address,1);
}
if(INPUT(PIN_C4)){
BIT_SET(address,2);
}
if(INPUT(PIN_C5)){
BIT_SET(address,3);
}
if(address = 0){
#define MODBUS_ADDRESS 0xF7
}else{
#define MODBUS_ADDRESS address
}
*/
while(TRUE)
{
if(modbus_kbhit()){modbus_check();}
for(i=0;i<8;i++){exc_hold[i] = maker(hold_regs[i]);} //byte exchange 0 to 1, 1 to 0
for(i=0;i<8;i++){input_regs[i] = maker(exc_input[i]);} //byte exchange 0 to 1, 1 to 0
pwm1_conf();
pwm2_conf();
/*
#define ONE_WIRE_PIN PIN_D7
value = ds1820_read(); //DS18B20 read procedure
printf(lcd_putc,"Temp : %3.1f %cC ", value, 223);
temp1 = (signed int16) value*10;
exc_input[0] = temp1;
/*
index = &value;
for(i=0;i<4;i++)
value0=make8(value32,0);
value1=make8(value32,1);
value2=make8(value32,2);
value3=make8(value32,3);
exc_input[0] = make16(value1,value0);
exc_input[1] = make16(value3,value2);
*/
//#define ONE_WIRE_PIN PIN_B6
if(ds_counter >= 250){
ds_counter = 0;
value = ds1820_read(); //DS18B20 read procedure
exc_input[0] = (signed int16)(value*10);
//lcd_gotoxy(1,1);
//printf(lcd_putc,"Temp : %3.1f %cC ", value, 223);
//temp2 = (signed int16) value*10;
}else{ds_counter++;}
/*
for(i=0;i<4;i++){
temp[i]=*(index+i);
}
exc_input[0] = make16(temp[1],temp[0]);
exc_input[1] = make16(temp[3],temp[2]);
//exc_input[2] = make16(make8(value,1),make8(value,0));
//exc_input[3] = make16(make8(value,3),make8(value,2));
*/
rateold = rate;
rate2old = rate2;
freq_old = freq;
freq2_old = freq2;
}
} |
Modbus.c
++++++++++++++++++++++++++++
Modbus.c, ex_modbus_slave.c, code deleted.
Reason: Forum rule #10
10. Don't post the CCS example code or drivers
http://www.ccsinfo.com/forum/viewtopic.php?t=26245
- Forum Moderator
++++++++++++++++++++++++++++ _________________ just think |
|