ADC_read() and ATtiny45

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
Andreasrothe
Posts: 5
Joined: 08 Mar 2016 14:03

ADC_read() and ATtiny45

#1 Post by Andreasrothe » 20 May 2016 08:54

Hi everybody.

I would like to read an analog signal ( 0-5V) and vary the PWM duty with it.

ADC_read() 0-5Volt is PWM_duty 0-100%.

My code is
After I bricked all my 328 and mega8 and mega88 aso. I changed to the ATtiny45.

I am using the EasyAVR6 board and MikroC and an ATtiny45

I can get a fixed value for the duty but I want a variable one due to the ADC input

What am I doing wrong??

here's the code:

#include <built_in.h>
unsigned int current_duty;
unsigned int current_duty1;
void main(){
current_duty = 20; // initial value for current_duty
DDB0_bit = 1; // Set PORTB pin 0 as output pin for the PWM (according to datasheet)
DDB1_bit = 0; // Set PORTB pin 1 as input
DDB2_bit = 0; // Set PORTB pin 2 as input
DDB3_bit = 0; // Set PORTB pin 3 as input
DDB4_bit = 0; // Set PORTB pin 4 as input
PWM1_Init(_PWM1_FAST_MODE, _PWM1_PRESCALER_1, _PWM1_NON_INVERTED, current_duty);
do {
current_duty1 = ADC_READ(0) ;
current_duty = current_duty1/4;
PWM1_Set_Duty(current_duty); // Set current duty for PWM1
} while(1); // Endless loop

}

help is very much appreciated

Regards

Andy

Post Reply

Return to “mikroC PRO for AVR General”