This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:examples:sensor:potentiometer [2015/11/09 14:21] – heikopikner | en:examples:sensor:potentiometer [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ~~PB~~ | + | < |
| - | ====== | + | ====== |
| - | //Necessary knowledge : [HW] [[en: | + | //Necessary knowledge: |
| + | [HW] [[en: | ||
| + | [ELC] [[en: | ||
| + | [AVR] [[en: | ||
| + | [LIB] [[en: | ||
| ===== Theory ===== | ===== Theory ===== | ||
| Line 28: | Line 32: | ||
| <code c> | <code c> | ||
| - | // | ||
| // Starting the ADC | // Starting the ADC | ||
| - | // | ||
| void adc_init(adc_reference reference, adc_prescale prescale) | void adc_init(adc_reference reference, adc_prescale prescale) | ||
| { | { | ||
| Line 40: | Line 42: | ||
| } | } | ||
| - | // | ||
| // Converting the values of selected channel | // Converting the values of selected channel | ||
| - | // | ||
| unsigned short adc_get_value(unsigned char channel) | unsigned short adc_get_value(unsigned char channel) | ||
| { | { | ||
| Line 64: | Line 64: | ||
| In previously explained example program analogue-digital converter and 7 segment number indicator library are used. The value of analogue-digital converter is multiplied by 10 and divided by 2048 to get the value between 0 and 9. The value 10 is impossible to reach because while dividing in C-language only integer value is calculated and not rounded result. Function of averaging the result of converter is used to get more accurate result. Derived from this the operating program shows the numbers 0 to 9, which correspond to the position of the potentiometer on the indicator. | In previously explained example program analogue-digital converter and 7 segment number indicator library are used. The value of analogue-digital converter is multiplied by 10 and divided by 2048 to get the value between 0 and 9. The value 10 is impossible to reach because while dividing in C-language only integer value is calculated and not rounded result. Function of averaging the result of converter is used to get more accurate result. Derived from this the operating program shows the numbers 0 to 9, which correspond to the position of the potentiometer on the indicator. | ||
| + | It should be noticed where is connected to the analog potentiometer in the particular hardware. For example, it is connected to an analog channel 3 in case of the Homelab Sensor Module II and analog channel 15th in case of the Home Labor III Interface module. | ||
| <code c> | <code c> | ||
| Line 86: | Line 87: | ||
| // Adjusting ADC | // Adjusting ADC | ||
| - | adc_init(ADC_REF_AVCC, | + | adc_init(ADC_REF_AVCC, |
| // Endless loop | // Endless loop | ||
| - | while (true) | + | while (1) |
| { | { | ||
| // Reading 4 times rounded values of the channel | // Reading 4 times rounded values of the channel | ||