yes, that would work, thank you, I will try that first thing in the morning tomorrowI will, of course, let you know.
Thanks again for the help, really appreciate !
yes, that would work, thank you, I will try that first thing in the morning tomorrowI will, of course, let you know.
Thanks again for the help, really appreciate !
I have tried this, and it is still at 68% duty cycle maximum... I also tried with a 4MHz oscillator and PTCON0 = 0, and it gives also 68%.
What are we missing ?![]()
Getting desesperate as I thought this would work but it seems it's not really the problem.. is it ?
Have you checked the output of your potentiometer? It works just as expected for me from 0 to 100% duty-cycle on an 18F4431 @ 20MHz.
Try the attached without making any changes.
PCPWM_AD.txt
Thanks it is working now, I made a huge mistake that I am so ashamed to make you waste your time with me. I am testing everything on a breadboard and my potentiometer was still connected to a resistance somewhere... I feel silly. Well at least it is working.
I am grateful for your time and your patience.
I am now getting started with my commutation sequence. Thank you again !
Even if this pic is complicated, I'm starting to see how powerful it is.
Been there - done that - just spank yourself, take notes & move on...I made a huge mistake![]()
I did
Hi again !
I would like your opinions guys in terms of "state of the art" way to write a picbasic pro program
I am getting inputs from an encoder, I have 12 positions possible, therefore 12 values. here is an example of my code for 2 values. I was wondering if the use of "Case" would be a better idea, that way if I decide to turn off my "switch" my program stops immediatly and is not finishing its loop before seeing that the switch's value changed.
Getadc is my subroutine for my pot and pwm to adjust the duty cycle regarding the value of the pot.Code:encoderstate1 var Byte duty var Word Main: encoderstate1 = PORTA If switch = 1 Then If encoderstate = 0 Then GoSub GetADC GoSub SetPWM OVDCOND = %00100010 'Q4 (PWM5) and Q10 (PWM1) PORTC = %00000011 'Q1 and Q7 ON EndIf If encoderstate1 = 1 Then GoSub GetADC GoSub SetPWM OVDCOND = %00000110 PORTC = %00001100 EndIf GoTo Main
Suggestions ?
Hi,
Sure, Select-Case is an option. It's "cleaner" but does result in slightly larger code than multiple IF-THEN statements. But if you're not short on space go ahead.
Another option might be to use BRANCH.
Also, perhaps you can move the GOSUB GetADC and GOSUB SetPWM to right after the If Switch=1 Then statement? That will save you a couple of bytes of program space and since, if I'm not mistaken, all twelve different encoder states calls both those routines you might as well do before evaluting the encoder value.
/Henrik.
Bookmarks