PWM using controller

Thread Starter

RenesasT1

Joined Jul 6, 2017
107
Ok. Try to implement on ATtiny25. I will take reference of the code and will try to implement the same on ATtiny10 and will share the results.

For ATtiny10 - Atmel studio compiler is used.
 

jayanthd

Joined Jul 4, 2015
945
Ok. Try to implement on ATtiny25. I will take reference of the code and will try to implement the same on ATtiny10 and will share the results.

For ATtiny10 - Atmel studio compiler is used.
No, you will not be able to get any idea from my ATTiny25 mikroC PRO AVR code because it uses compiled libraries for adc and pwm. code is small, just 30 lines of C Code. Coding is almost complete. The PWM library functions are a little complex. I will have a chat with mikroE support and get a sample code to generate 100 Hz PWM using mikroC PRO AVR. I will provide you the code today.
 
Last edited:

Thread Starter

RenesasT1

Joined Jul 6, 2017
107
Hello,

If you are giving me code for i/p as a ADC and o/p as a PWM then I have done that case.

Please give me code to measure duty cycle of PWM at i/p of micro controller and o/p is also PWM.

Now I am ready to take two different pins for ADC i/p and PWM i/p.

I dont wanted to use low pass filter. Please let me know the detail.
 

jayanthd

Joined Jul 4, 2015
945
Hello,

If you are giving me code for i/p as a ADC and o/p as a PWM then I have done that case.

Please give me code to measure duty cycle of PWM at i/p of micro controller and o/p is also PWM.

Now I am ready to take two different pins for ADC i/p and PWM i/p.

I dont wanted to use low pass filter. Please let me know the detail.
Ok. I thought you want to use low pass filter method. If you can use different pins for ADC i/p, PWM i/p and PWM o/p then I will write a new code and send it to you tonight. Still to generate PWM of 100 Hz using mikroC library I have to get support from mikroE.

I was writing code to use two adc channels for adc i/p 1 and low pass filter to adc method.


This was the code I was writing.

C:
unsigned int raw_adc_value[2] = {0, 0}, old_raw_adc_value[2] = {0, 0};
unsigned short pwm_duty = 0;
char i = 0;

void main() {

    DDRB = 0x1B;
    PORTB = 0x00;
   
    Delay_ms(100);
   
    //PWM1 Initialization 100 Hz
    //PWM Duty 0
    //PWM1 Start
   
    while(1) {
   
          for(i = 0; i < 2; i++) {
              raw_adc_value[i] = ADC_Read(i);
              Delay_us(80);
          }

          for(i = 0; i < 2; i++) {
             if( (old_raw_adc_value[i] != raw_adc_value[i]) 
                && (raw_adc_value[i] > 0) 
                && (raw_adc_value[(~i) & 1] == 0)) {
                 //PWM1 Set Duty
                 
                 old_raw_adc_value[i] = raw_adc_value[i];
             }
          }
    }
}
 

Thread Starter

RenesasT1

Joined Jul 6, 2017
107
Hello,

As I said. Forget about ADC.

Consider I have external PWM square wave generator as i/p and at o/p I have LED.

I dont want to use low pass filter at i/p. Directly i/p PWM will go to the microcontroller PWM.

Please forget about 100Hz at o/p. I will generate 100Hz at o/p/

My issue is at i/p. How to measure the duty cycle of i/p PWM from external source. I dont know the code for the same.

According to duty at i/p PWM the duty of o/p will set. I will generate 100Hz duty. Please tell me about i/p side.
 

jayanthd

Joined Jul 4, 2015
945
Hello,
Please forget about 100Hz at o/p. I will generate 100Hz at o/p/

According to duty at i/p PWM the duty of o/p will set. I will generate 100Hz duty. Please tell me about i/p side.
100 Hz o/p PWM is needed ?

PWM duty is not in Hz. It is in % (0-100%)

0% means PWM off
100% means PWM full ON.

Ok. I will make a code using ATTiny25. Still I need to contact mikroE regarding the usage of PWm library of mikroC PRO AVR because there are many different PWM libraries.
 

jayanthd

Joined Jul 4, 2015
945
OK.Thanks.I will wait for your update.
I have asked mikroE for an example code which generated 100 Hz PWM with 0-100% duty.

I just checked some devices and found this cheaper device which has 3x 16-bit PWMs with independant timers. It is cheaper than ATTiny25. Can you use it instead of ATTiny25 ?

I am familiar with PIC and I can help you with a PIC code (mikroC PRO PIC).

https://www.microchipdirect.com/ProductDetails.aspx?Category=ATtiny25

http://www.microchipdirect.com/ProductDetails.aspx?Category=PIC12F1572&&keywords=PIC12F1572-I/MS
 

jayanthd

Joined Jul 4, 2015
945
My ATtiny 10 has only one 16 bit timer.
Are you reverse engineering a product ?

Do you want exact 100 Hz output PWM frequency and precise PWM duty mapping from input to output or can it vary a little ? If it can vary then how much ?

email me at (email address removed by moderator -please convey email addresses privately)
 
Last edited by a moderator:
Top