|
|
View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Jan 31, 2023 3:06 am |
|
|
You have a #USE RS232, and printf's shown in what you have posted. |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Tue Jan 31, 2023 3:31 am |
|
|
Ttelmah wrote: | You have a #USE RS232, and printf's shown in what you have posted. |
Ok i see, so ERROR is only for my printf on terminal? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Jan 31, 2023 6:28 am |
|
|
simply said...
ERRORS is for incoming (receive) data To the PIC.
Without it, the PIC HW UART will 'freeze' (stop) the PIC from running
Think of the incoming buffer as your mailbox, that can only contain 5 letters. If YOU don't take at least ONE of those 5 letters out, then you can't get anymore mail.
If you code and compile a small program without and with 'ERRORS', then look at the listings, you'll see what the additional code is doing. Yes, it'll be in assembler but it's easy to decode.
Sadly it should be a default parameter but it's not. |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Wed Feb 01, 2023 2:24 pm |
|
|
temtronic wrote: | simply said...
ERRORS is for incoming (receive) data To the PIC.
Without it, the PIC HW UART will 'freeze' (stop) the PIC from running
Think of the incoming buffer as your mailbox, that can only contain 5 letters. If YOU don't take at least ONE of those 5 letters out, then you can't get anymore mail.
If you code and compile a small program without and with 'ERRORS', then look at the listings, you'll see what the additional code is doing. Yes, it'll be in assembler but it's easy to decode.
Sadly it should be a default parameter but it's not. |
Okay i will add the options. I have noticed something yesterday, my code use currently 67% of ROM, and i don't know from what value PIC can have problems and what problems can appear? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Feb 01, 2023 3:13 pm |
|
|
If the program compiles, then you can fill the ROM with 'program'. Technically you will not get problems. Your program fits into the ROM.
Normally what happens is, depending on the PIC, you can get a 'segment too large' error(so will NOT compile) which indicates that a 'section' of your code (say a large or complicated function ) is too long(big) to fit into a segment or 'section' of the ROM. Now, providing there IS physical room for the code, you can usually 'juggle' or rearrange the order of the functions, or use other 'tricks' to get the program to fit. |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Mon Feb 20, 2023 2:48 am |
|
|
Hello, i hope you are all going well. I am back on project and i wanna try to use better the "atan" function in purpose to reduce the space used. One of you told me there is exemple in code library but i don't find it. Could someone help me? Best regards. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Mon Feb 20, 2023 3:19 am |
|
|
It's an equivalent to atan2, not atan.
[url]
http://www.ccsinfo.com/forum/viewtopic.php?t=56264
[/url]
atan2, is generally what you need for things like this. Two measurements,
X and Y, and you want the angle this corresponds to. |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Mon Feb 20, 2023 10:02 am |
|
|
ok, so i've checked your link, i just don't understand properly those lines :
Code: |
//Now approximation for atan from -1 to +1, giving an answer in degrees.
aival = fAbs(ival);
oval = 45 * ival - ival * (aival - 1) * (14.02 + 3.79 * aival);
|
they are replacing atan2 right?
but what does aival, ivaland oval mean? |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Mon Feb 20, 2023 10:03 am |
|
|
ok, so i've checked your link, i just don't understand properly those lines :
Code: |
//Now approximation for atan from -1 to +1, giving an answer in degrees.
aival = fAbs(ival);
oval = 45 * ival - ival * (aival - 1) * (14.02 + 3.79 * aival);
|
they are replacing atan2 right?
but what does aival, ival and oval mean? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Mon Feb 20, 2023 10:42 am |
|
|
They are internal variables in the function.
Declared at the top of the function.
A search online will find the algorithm this uses. Remember the factors
are tweaked to give a result in degrees, not radians, since most
applications for sensors like yours will actually want degrees as a result. |
|
|
AKA TENDO
Joined: 25 Jan 2023 Posts: 47
|
|
Posted: Fri Nov 17, 2023 2:19 pm |
|
|
Hi everybody. First, i would say thank you to all of you guys who helped me for my project. It kind or worked i just had other problems but i have mainly reached my goal. I just realised that i forgot to say thank you and post my final code. So, i ll do it now. I hope this is the good code, in other way it should still help people with same problem :
Code: | #include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use i2c(MASTER, sda=PIN_C4, scl=PIN_C3)
#include <MATH.h>
#define MPU6050_SLAVE_WRT 0xD0
#define MPU6050_SLAVE_RD 0xD1
// Register addresses
#define MPU6050_WHO_AM_I 0x05
#define MPU6050_SMPLRT_DIV 0x19
#define MPU6050_CONFIG 0x1A
#define MPU6050_GYRO_CONFIG 0x1B
#define MPU6050_PWR_MGMT_1 0x6B
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
// Global variables
int order = 0;
signed int16 accel_xout;
signed int16 accel_yout;
signed int16 accel_zout;
float accel_xangle;
float accel_yangle;
/////////////////////////////////////////////////////
//WRITE SLAVE//
/////////////////////////////////////////////////////
void write_slave(int add, int val)
{
i2c_start();
i2c_write(add);
i2c_write(val);
i2c_stop();
delay_ms(100);
}
/////////////////////////////////////////////////////
//Slave_Handler//
/////////////////////////////////////////////////////
void Slave_Handler()
{
//int valCompare1, valCompare2, valCompare3;
//Angle_X//
if (accel_xangle <= (-5))
{
order = 1;
}
if (accel_xangle >= (-3))
{
order = 2;
}
if ((accel_xangle <= (-3)) && (accel_xangle >= (-5)))
{
order = 0;
}
printf("order= %d \n\r", order);
}
//Angle_Y//
/*if (accel_yangle <= (-3))
{
order = 1;
}
if (accel_yangle >= 0)
{
order = 2;
}
}
*/
/////////////////////////////////////////////////////
//READ WORD//
/////////////////////////////////////////////////////
int16 MPU6050_read_word(int8 reg_addr)
{
int8 lsb, msb;
int16 retval;
i2c_start();
i2c_write(MPU6050_SLAVE_WRT);
i2c_write(reg_addr);
i2c_start();
i2c_write(MPU6050_SLAVE_RD);
msb = i2c_read(); // Read MSB byte first.
lsb = i2c_read(0); // Do a NACK on the last read
i2c_stop();
retval = make16(msb, lsb);
return(retval);
}
/////////////////////////////////////////////////////
//ACCEL VALUES//
/////////////////////////////////////////////////////
void Get_Accel_Values()
{
accel_xout = MPU6050_read_word(ACCEL_XOUT_H);
accel_yout = MPU6050_read_word(ACCEL_YOUT_H);
accel_zout = MPU6050_read_word(ACCEL_ZOUT_H);
}
/////////////////////////////////////////////////////
//GET ANGLES//
/////////////////////////////////////////////////////
void Get_Accel_Angles()
{
accel_xangle = 57.295*atan((float)accel_yout/ sqrt(pow((float)accel_zout,2)+pow((float)accel_xout,2)));
accel_yangle = 57.295*atan((float)-accel_xout/ sqrt(pow((float)accel_zout,2)+pow((float)accel_yout,2)));
}
/////////////////////////////////////////////////////
//MPU INIT//
/////////////////////////////////////////////////////
void Setup_mpu6050(void)
{
delay_ms(100);
i2c_start();
i2c_write(MPU6050_SLAVE_WRT);
i2c_write(MPU6050_PWR_MGMT_1);
i2c_write(0x00);
i2c_stop();
i2c_start();
i2c_write(MPU6050_SLAVE_WRT);
i2c_write(MPU6050_GYRO_CONFIG);
i2c_write(0x08);
i2c_stop();
i2c_start();
i2c_write(MPU6050_SLAVE_WRT);
i2c_write(MPU6050_SMPLRT_DIV);
i2c_write(0x07);
i2c_stop();
delay_ms(100); // Gyro start-up time is 30ms after power-up.
}
/////////////////////////////////////////////////////
// MAIN //
/////////////////////////////////////////////////////
void main()
{
Setup_mpu6050();
while(TRUE)
{
Get_Accel_Values();
Get_Accel_Angles();
delay_ms(200);
Slave_Handler();
output_d(input_b());
write_slave(0x17,order1);
write_slave(0x21,order2);
printf("accel_xangle = %7.0f \n\r", accel_xangle);
printf("accel_yangle = %7.0f \n\r", accel_yangle);
printf("\n\r");
delay_ms(300);
}
} |
I know my code isn't very good but i hope it will help. Yo could at least use my functions. Best regards and thank you all. |
|
|
nayos89
Joined: 24 Aug 2024 Posts: 1
|
|
Posted: Fri Nov 15, 2024 4:34 am |
|
|
[quote="AKA TENDO"] PrinceNai wrote: | Let's presume the plank doesn't bend. I'd place two sensors aligned on the plank border along x axis, and one on the opposite side, in a triangle formation, all sensors having x and y axis facing the same directions. Here I noticed you actually need only two actuators, one corner can be fixed. Then lift or lower the actuator on x axis so that both sensors there read 0 degrees. You are done with leveling on that axis. Than you lift or lower the actuator on the opposite side of the plank so that y axis reading from that and any other sensor reads 0 deg. You have a leveled plank.
I'm not sure if I explained it good enough, but that is the way we level cylinders in the casino, only instead of actuators we use a technician.
Can of course be done with only one sensor, it's just my one-track thinking you'd need three :-)
Greetings! A friend from Cape Coast suggested I visit https://aviators.com.gh/1xbet to try the Aviator game. I decided to take the plunge and was immediately entertained by the game’s unique concept. Despite a few initial losses, persistence paid off when I landed a great win that boosted my confidence. It’s a fun and rewarding way to spend some time in Ghana, and I highly recommend it to anyone looking for an exciting casino game. |
thanks for the good info |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|