Phase and Frequency Correct PWM setup

dannyf

Joined Sep 13, 2015
2,197
I have scoured the data sheet all I can see is that OCR1C is used as the (TOP) value I assume for all the registers.
1) read the datasheet;
2) state in plain english what registers need to be set to what values for your application;
3) translate that in the code.
4) done.
 

jayanthd

Joined Jul 4, 2015
945
I think you are loading only 8 bit value of the 10 bit result of ADC to PWM register. I have experienced similar problem in PIC. If PWM registers are 8 bit then you have to scale 10 bit ADC result to 8 bit by right shifting 2 times and then load it to your PWM register.
 

dannyf

Joined Sep 13, 2015
2,197
OUT OCR1D, PWa
here is all it takes to do in C:

Code:
    pwm1b_init();                           //initialize pwm1b, 2x dtps, 256:1 prescaler, ocr1c=256, dual slope pwm
    pwm1b_setdc(100);                       //set dc to 100/256.
and here is the output, @ 8Mhz intrc, 8:1.
attiny261_pwm1b_dualslope.PNG

the point? move to C before it is too late.
 

Thread Starter

LaurenceR

Joined Feb 7, 2013
107
Today was a good day. I have to thank everyone for their patience and intelligent guidance. It all helped. I made a few coding mistakes however that's what forces you to look carefully at each register. I have it working perfectly now and all the math proves out as well.

Many thanks to everyone.

I haven't given the above software a try yet as I like to stick with assembly basics. It's certainly worth trying out. Thanks again.
 
Top