1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

AVR Programming interface Outline

Discussion in 'DIY Motion Simulator Projects' started by stowaway, Feb 18, 2012.

  1. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    Ive drawn up a little outline of what how i think my interface will work.

    I know how to read binary from serial, read pots via ADC, and output PWM. I have a winch motor on order and 2 professionally etched Tronic H-Bridges.. So hopefully I can start to put things together.

    can those microcontroller gurus out there tell me if im on the right path with my outline?

    I havent included alot in there, for example the POT will be much higher resolution that the 8bit PWM channels I will have, so I will need conversations etc..

    arduinoCode.jpg
  2. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    I found the Atmel PID.c PID.h source files.. ive implemented them to a little test proggie:

    I find it takes a lot more cycles than I think it should to settle at the correct value

    Code:
    
    #include <avr/io.h> 
    #include <stdio.h>
    #include <stdlib.h>
    #include <util/delay.h>
    #include <avr/interrupt.h>
    #include pid.h
    #include lcd.h
    #include <string.h>
    
    #define NO_OF_POTS 3
    #define potSensitivity 10
    
    //To Do. make these values editable via lcd and buttons
    double K_P = 3;
    double K_I = 5;
    double K_D = 3;
    
    
    struct PID_DATA pidData1;
    
    
    
    
    
    void Init(void)
    {
    	//Setup PID structs
    	pid_Init(K_P, K_I, K_D, &pidData1);
      
      
    	/* Init LCD */
    	lcd_init(LCD_DISP_ON);
    	
    	lcd_clrscr();
    	lcd_puts(Init Okay);
    	
    	
       
    }
    
    int DoPid(int16_t desiredValue, int16_t acualValue, struct PID_DATA *pidData)
    {
    	return pid_Controller(desiredValue, acualValue, pidData);
    }
    
    int main(void)
    {
    	Init();
    	int desiredPosition = 500;
    	int actualPosition = 200;
    		
    	while (1)
    	{
    	
    	
    	
    		
    		if (1)
    		{		
    			char potString[7];						
    			char LCDline2[17];
    			
    			
    			int PWMvalue = DoPid(desiredPosition, actualPosition, &pidData1);
    			
    			
    			itoa(actualPosition, potString, 10);						
    			
    			itoa(PWMvalue, LCDline2, 10);
    			
    			lcd_clrscr();					
    			lcd_puts(potString);
    			lcd_gotoxy(0,1);
    			lcd_puts(LCDline2);
    
    			actualPosition += PWMvalue;
    			_delay_ms(100);
    			
    			
    		}
    		
    		
    		
    		
    	}
    }