changed ReadADC() into ReadFader(). Added ReadSpeed() function and documentation.
				
					
				
			This commit is contained in:
		
							parent
							
								
									a88fae412e
								
							
						
					
					
						commit
						724237147f
					
				
					 2 changed files with 26 additions and 6 deletions
				
			
		
							
								
								
									
										11
									
								
								inc/main.h
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								inc/main.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -42,6 +42,7 @@
 | 
			
		|||
#define PWM_PIN1 PB0  // Pin 5 - Motor PWM 1
 | 
			
		||||
#define PWM_PIN2 PB1  // Pin 6 - Motor PWM 2
 | 
			
		||||
#define ADC_PIN PB3   // Pin 2 - Fader position reading
 | 
			
		||||
#define SPEED_PIN PB2 // Pin 7/ADC1
 | 
			
		||||
#define BUTTON_PIN PB4 // Pin 3 - Button input
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -97,9 +98,15 @@ void InitProg(void);
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Reads the ADC pin
 | 
			
		||||
 * @brief Reads the ADC pin from the fader.
 | 
			
		||||
 */
 | 
			
		||||
uint16_t ReadADC(void);
 | 
			
		||||
uint16_t ReadFader(void);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Reads the ADC value from the Speed pot.
 | 
			
		||||
 */
 | 
			
		||||
uint16_t ReadSpeed(void);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										21
									
								
								src/main.c
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								src/main.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -83,7 +83,20 @@ void InitProg(void) {
 | 
			
		|||
  InitTimer0();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint16_t ReadADC(void) {
 | 
			
		||||
uint16_t ReadSpeed(void) {
 | 
			
		||||
  // Initialize ADC
 | 
			
		||||
  ADMUX = (0 << MUX1) | (1 << MUX0);                  // Select ADC1 (PB2)
 | 
			
		||||
  ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8
 | 
			
		||||
 | 
			
		||||
  ADCSRA |= (1 << ADSC); // Start conversion
 | 
			
		||||
  while (ADCSRA & (1 << ADSC)) {
 | 
			
		||||
  } // Wait for conversion to finish
 | 
			
		||||
  return ADC;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//change to ReadFader(void)
 | 
			
		||||
uint16_t ReadFader(void) {
 | 
			
		||||
  // Initialize ADC
 | 
			
		||||
  ADMUX = (1 << MUX1) | (1 << MUX0);                  // Select ADC3 (PB3)
 | 
			
		||||
  ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8
 | 
			
		||||
| 
						 | 
				
			
			@ -108,7 +121,7 @@ static inline uint8_t diff(uint8_t a, uint8_t b) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void MotorSetSavePos() {
 | 
			
		||||
  uint8_t pos = (uint8_t)(ReadADC() >> 2);
 | 
			
		||||
  uint8_t pos = (uint8_t)(ReadFader() >> 2);
 | 
			
		||||
  eeprom_write_byte((uint8_t *)ROM_SS1_ADR, pos);
 | 
			
		||||
  return;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -119,10 +132,10 @@ uint8_t MotorGetSavedPos(void) {
 | 
			
		|||
 | 
			
		||||
void MotorMoveTo(uint8_t target) {
 | 
			
		||||
 | 
			
		||||
  uint8_t pos = (uint8_t)(ReadADC() >> 2);
 | 
			
		||||
  uint8_t pos = (uint8_t)(ReadFader() >> 2);
 | 
			
		||||
 | 
			
		||||
  while (diff(target, pos) > 8) {
 | 
			
		||||
    pos = (uint8_t)(ReadADC() >> 2);
 | 
			
		||||
    pos = (uint8_t)(ReadFader() >> 2);
 | 
			
		||||
    if (target > pos) {
 | 
			
		||||
      MotorMove(1);
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue