Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 19, 2024, 10:15:12 22:15


Login with username, password and session length


Pages: [1]
Print
Author Topic: I see Errors A full CCS C RTOS based PID and random generator project  (Read 2660 times)
0 Members and 1 Guest are viewing this topic.
comlekciler
Junior Member
**
Offline Offline

Posts: 40

Thank You
-Given: 73
-Receive: 44

Ph.D.


« on: September 26, 2020, 08:15:09 20:15 »

Didn't you forget to add the project files, right? When I downloaded the file content was as in the picture. Couldn't I see it? Roll Eyes
Logged

...none...
moffolb
Newbie
*
Offline Offline

Posts: 23

Thank You
-Given: 72
-Receive: 66


« Reply #1 on: September 26, 2020, 08:55:47 20:55 »

Didn't you forget to add the project files, right? When I downloaded the file content was as in the picture. Couldn't I see it? Roll Eyes


Look at the picture well, the project file is the file with name “random_num.pdsprj”
Logged
hosmis
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 326
-Receive: 243


« Reply #2 on: September 26, 2020, 09:21:26 21:21 »

Run_num.c


#include <Ran_Num.h>


void main()
{

   while(TRUE)
   {




      //TODO: User Code
   }

}



 Cool
Logged
comlekciler
Junior Member
**
Offline Offline

Posts: 40

Thank You
-Given: 73
-Receive: 44

Ph.D.


« Reply #3 on: September 27, 2020, 10:03:05 10:03 »

Look at the picture well, the project file is the file with name “random_num.pdsprj”
I didn't ask about the ISIS project. I meant files with source code (* .c, * .h).
Logged

...none...
pickit2
Moderator
Hero Member
*****
Offline Offline

Posts: 4647

Thank You
-Given: 826
-Receive: 4207


There is no evidence that I muted SoNsIvRi


« Reply #4 on: September 27, 2020, 12:58:46 12:58 »

I didn't ask about the ISIS project. I meant files with source code (* .c, * .h).
Did you read the Post?
All the files are there.
Logged

Note: I stoped Muteing bad members OK I now put thier account in sleep mode
hosmis
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 326
-Receive: 243


« Reply #5 on: September 27, 2020, 01:10:29 13:10 »

interesting...
I guess version difference

« Last Edit: September 27, 2020, 01:31:10 13:31 by hosmis » Logged
comlekciler
Junior Member
**
Offline Offline

Posts: 40

Thank You
-Given: 73
-Receive: 44

Ph.D.


« Reply #6 on: September 27, 2020, 02:26:56 14:26 »

It looks hollow to me too. As hosmis said, I guess it's due to the version. Sorry.
Logged

...none...
hosmis
Active Member
***
Offline Offline

Posts: 173

Thank You
-Given: 326
-Receive: 243


« Reply #7 on: September 27, 2020, 04:20:36 16:20 »

Copy from Proteus source code
CCS paste c
is working

Code:
#include <Ran_Num.h>
#include <flex_lcd.c>
#include <string.h>
#use rtos(timer=0, minor_cycle=500us)

int count;
float Tex, Ksens_1, Tref, ek, ek_1, ek_2, uk, uk_1;
float Kp, Ki, Kd, a0, a1, a2, p0, p00,T,Tf;
int16 value;
float Consigne;

char BufferLCD1[16];                // Tampon pour écrire  sur la 1ère ligne de l'écran LCD
char BufferLCD2[16];                // Tampon pour écrire  sur la 2ème ligne de l'écran LCD
//int LengthMsj1, LengthMsj2;          // Longueur de chaîne
//char String[6];                      // Tampon pour stocker la conversion à imprimer

int8 sem;
//----------Declaratiion des Taches----------------------------------------------------------------
#task(rate=200ms, max=500us)
void Live() ;
#task(rate=10ms, max=500us, queue=1)
void Display() ;
#task(rate=10ms, max=500us, queue=1)
void Display_LCD() ;
#task(rate=1ms, max=500us)
void Generator() ;
#task(rate=10ms, max=500us, queue=1)
void Terminal() ;
#task(rate=1ms, max=500us)
void PID_Crt() ;
//----------Fin Declaratiion des Taches----------------------------------------------------------------
//----------Definitiion des fonctions-------------------------------------------------------------------

void Inf_To_LCD();

//----------Fin Definitiion des fonctions---------------------------------------------------------------

//----------Implementation des Taches----------------------------------------------------------------
void Live() {
output_toggle(LED_Liv);
}

void Display() {
if(rtos_msg_poll() > 0){ // Is there a message ?
output_d(rtos_msg_read()); // Send to PORTD
}
}

void Display_LCD() {
/*if(rtos_msg_poll() > 0){ // Is there a message ?
printf(lcd_putc,"\fCur Numb: %U\n", rtos_msg_read()); // Send to PORTB
}*/
rtos_wait(sem);
printf(lcd_putc,"\f");
printf(lcd_putc,BufferLCD1);
lcd_gotoxy(1,2);
printf(lcd_putc,BufferLCD2);
}

void Generator() {
char Car;
count++;
if(input(BP) == 0) {
rtos_await(input(BP) == 1);
Inf_To_LCD();
rtos_signal(sem);
}
if(kbhit()){
Car = getch();
if(Car == 'N'){
Inf_To_LCD();
rtos_signal(sem);
}
if(Car == 'C'){
scanf("%f",&Tref);
sprintf(BufferLCD2,"SetPoint = %3.1f",Tref);
rtos_signal(sem);
}
}
}

void Terminal(){
if(rtos_msg_poll() > 0){ // Is there a message ?
printf("\n\rNumb = %u \n\r",rtos_msg_read());
}
}

void PID_Crt() { // Controlleur PID
float PWM_Out;
value = read_adc();
Tex = value;
Tex = Tex * 0.004883 * Ksens_1; // Tex = Uin * Quantum * (1/Ksensor)
ek = Tref - Tex ; // Erreur de Commande
uk = uk_1 + a0*ek - a1*ek_1 + a2*ek_2; // Calcul de la commande
PWM_Out = uk*800; // Conversion en alpha pour la commande PWM
if(uk < 0){ // Gestion de la saturation de la commande
uk = uk*p00;
PWM_Out = 0;}
if(uk > 1){
uk = (uk + p0)*p00;
PWM_Out = 800;}
value = PWM_Out;
set_pwm1_duty(value); // Application de la commande
uk_1 = uk; // Mise a jour des futur valeurs
ek_2 = ek_1;
ek_1 = ek;
}

//----------Fin Implementation des Taches----------------------------------------------------------------

void Inf_To_LCD(){ //---Utiilise par la Tache Generator----------
rtos_msg_send(Display,count);
rtos_msg_send(Terminal,count);
sprintf(BufferLCD1,"Count = %U",count);
sprintf(BufferLCD2,"SetPoint = %3.1f",Tref);
}

void Init_PID_Par(){ //--Init des parametres du PID-------------
Ksens_1 = 74.1697;
Tref = 50.0;
Kp = 0.0909;
Ki = 2.502;   
Kd = 0.0006139;
T = 0.001;
uk_1 = 0.0;
ek_1 = 0.0;
ek_2 = 0.0;
Tf = 0.02599;
a0 = Kp + Ki*T + Kd/T;
a1 = Kp + 2*Kd/T;
a2 = Kd / T;
p0 = kp*T/ ki;
p00 = 1 / (1 + p0);
}

void main()
{
setup_adc_ports(sAN0, VSS_VDD);
//setup_adc(ADC_CLOCK_DIV_4 | ADC_TAD_MUL_4);
setup_adc(ADC_CLOCK_INTERNAL);            // Built-in A/D setup function
setup_timer_2(T2_DIV_BY_4,199,1);      //250 us overflow, 250 us interrupt  setup_timer_2(T2_DIV_BY_16,249,1);

setup_ccp1(CCP_PWM);
//set_pwm1_duty((int16)0);

lcd_init();
set_adc_channel(0);
Init_PID_Par();

sem = 0;

while(TRUE)
{
//TODO: User Code
rtos_run();
}
}
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC