Path: news.mathworks.com!not-for-mail
From: "Alp " <akacar2@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: RS-232 and RTWT
Date: Thu, 5 Nov 2009 10:27:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 70
Message-ID: <hcu99l$8l5$1@fred.mathworks.com>
References: <hcpv6r$3r4$1@fred.mathworks.com> <hcrepq$268h$1@ns.felk.cvut.cz>
Reply-To: "Alp " <akacar2@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257416821 8869 172.30.248.38 (5 Nov 2009 10:27:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 5 Nov 2009 10:27:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2072514
Xref: news.mathworks.com comp.soft-sys.matlab:582669


Thank you for your help. We tried your way ,but we cannot achived to get proper result. I am telling you our project with its details. I hope you can find our missings. We want to produce PWM signal (from B0 pin) from PIC according to coming signal from Simulink (0 to 1000). We used MAX232 IC for converting +12V,-12V to 5V,0V.
CCS C Program of PIC16F877:

#include <16f877.h>  
#include <stdlib.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=4000000)
#use rs232 (baud=9600, xmit=pin_C6, rcv=pin_C7, parity=N, stop=1) 
#use fast_io(b)

long int A=63536;
char   klavye[16];  
int16 x=0;
#int_rda  
void serihaberlesme_kesmesi ()
{
   disable_interrupts(int_rda); 
   output_high(pin_c5); 
   gets(klavye);
   output_low(pin_c5); 
}
//****************** Timer1 Interrupt  (1-2 ms)  ****
#int_timer1  
void  timer1_kesme () 
{
    output_low(pin_b0);
}

//****************** Timer0 Interrupt (20 ms) *****
#int_timer0 
void  timer0_kesme () 
{
    output_high(pin_b0);
    set_timer0(177);   // TMR0
    set_timer1(A);   // TMR1
}

void main ( )
{
   setup_psp(PSP_DISABLED);      
   setup_timer_2(T2_DISABLED,0,1); 
   setup_CCP1(CCP_OFF);         
   setup_CCP2(CCP_OFF);          
   setup_adc_ports(NO_ANALOGS);  
   setup_adc(ADC_OFF);      
   
   set_tris_b(0x00); 
   output_b(0x00);   
    
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256);   // Timer0 
   set_timer0(177);     // TMR0 
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);   // Timer1 
   enable_interrupts(INT_timer1); 
   enable_interrupts(INT_timer0); 
   enable_interrupts(GLOBAL);  


   while(1) 
   {
   x=atol(klavye);
   A=64536-x;
   enable_interrupts(int_rda);
   }
}

Simulink File:

Constant-->Slider Gain-->Stream Output (or Packet Output)

Thank you again..