Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!kanja.arnes.si!news-hub.siol.net!newsfeed1.eu.ignite.net!news.cesnet.cz!news.felk.cvut.cz!not-for-mail
From: Jan Houska <houska@humusoft.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: RS-232 and RTWT
Date: Thu, 05 Nov 2009 12:09:35 +0100
Organization: HUMUSOFT s.r.o.
Lines: 100
Message-ID: <hcubpg$bei$1@ns.felk.cvut.cz>
References: <hcpv6r$3r4$1@fred.mathworks.com> <hcrepq$268h$1@ns.felk.cvut.cz> <hcu99l$8l5$1@fred.mathworks.com>
NNTP-Posting-Host: hack.humusoft.cz
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: ns.felk.cvut.cz 1257419376 11730 88.208.79.130 (5 Nov 2009 11:09:36 GMT)
X-Complaints-To: usenet@news.felk.cvut.cz
NNTP-Posting-Date: Thu, 5 Nov 2009 11:09:36 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.18 (Windows/20081105)
In-Reply-To: <hcu99l$8l5$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:582676


Hi Alp,

have you been able to control your PIC from another Windows application 
- not MATLAB, not Real-Time Windows Target? What data format were you using?

 From the PIC code below it looks like the device expects the data in 
ASCII, so you would need to use Stream Output. Further, it looks like 
you are expecting an integer decimal number, so you should set the 
format string to '%d'. Of course, you must ensure that baud rate, bit 
length, parity, etc. settings of the PIC match those of Real-Time 
Windows Target (settable in Board Setup).

Other than this, I can't think of anything else at the moment. But I'd 
definitely start from a working setup (if you have any) and gradually 
change thing to the desired setup with Real-Time Windows Target.

Good Luck, Jan


Alp wrote:
> 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..


-- 

--
Jan Houska                                           HUMUSOFT s.r.o.
houska@humusoft.com                                  Pobrezni 20
http://www.humusoft.com                              186 00 Praha 8
tel: ++ 420 284 011 730                              Czech Republic
fax: ++ 420 284 011 740