Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F1936 ADC reading for variable PWM

Status
Not open for further replies.

jean12

Advanced Member level 2
Joined
Aug 27, 2013
Messages
529
Helped
5
Reputation
12
Reaction score
6
Trophy points
18
Activity points
5,497
Hello there could you please help me to handle the variation of PWM signal duty cycle using a potentiometer on RA0 of the 16F1936,I am using assembly and tried multiple time but I failed.please could you help?

I want to vary the PWM singal for CCP1,CCP2 and CCP3 of this microcontroller,I want to control the speed of ACIM(AC Induction Motor:Three phase),please help
 

Figure 23-3 in the data sheet shows the key timing variables and the duty cycle itself is discussed in Section 23.3.5. Given Equation 23-3 and that you generally need to keep the PRx register value fixed, you should be able to derive the formula to convert the duty cycle into the required "CCPRxL:CCPxCON<5:4>" value and set the registers accordingly.
However, before starting on that, you need to make sure that you are reading the potentiometer value correctly through the ADC. I suggest that you start with a program that initialises the ADC and, in the main loop, simply reads the ADC value for the pin connected to the potentiometer arm. One you can do them you can then convert that value into a percentage (or fraction) of the full scale value. Of course this is really the duty cycle.
The next step would be to then use that value to calculate the PWM value as mentioned above for one of the PWM devices. Once all that is working it should be very easy to extend the duty cycle setting to all 3 PWM peripherals.
Susan
 

The codes I have seem to be more complicated,I edited the one of AN889 from where they used PIC16F777 and this has 3 A/D Modules so with different steps they used the value read from the potentiometer to vary the frequency by establishing a relatioship;voltage varies from 0-5V (on the potentiometer) and the frequency of the system works at 0-60HZ but me I want to set it to work from 0-35HZ with a switching frequency of 10KHZ.

unfortunately the simple codes I implemented for reading the voltage from the potentiometer is not working with my simulation in proteus,could you please help??

Thank you!!
 

I have already suggested how you should approach this one step at a time.
Also, if you do have simple code to read the ADC value but it is not giving the correct result, then show us so that we can help get it right.
If at all possible, try running on real hardware rather than a simulator that itself may have bugs (I don't know in this case but the silicon is really what matters).
Susan
 

Hi jean

Which Compiler are you using ? If you mention details like Clock frequency etc I will write a code for you.
 

the codes I am running are the ones for V/F in order to control the speed of a three phase motor(asynchronous motor)so the potentiometer might be used for setting that ratio which is referred to for controlling the speed.

Find the link here https://www.edaboard.com/threads/347219/
 

Hello,with my adc reading problem see hat I am getting with proteus simulation(snapshot attached),unfortunately I set

ADCON0=0x0F
ADC0N1=0X20
with the first ADC error I tried to change the ADCON1 to 0X60 but still not working,when trying reading ADC only I succeed but with the PWM I failed,my quartz is of 20MHZ and the PWM generated is of 10KHZ.


Thank you!!
 

Attachments

  • Image.zip
    110.3 KB · Views: 104

A graph without axis and no explanation of what it is ???
You are supposed to be providing an analog voltage to the ADC and getting a digital number out of it so it isn't at all clear what the scope trace is showing.

As a guess, you have the left and right justification swapped over or are only using the bits in ADRESH and ignoring ADRESL.

Follow Susan's advice in post #4 and get the ADC working first. There is little point in trying to use the ADC data if you are not confident it is correct anyway.

Brian.
 

Timer Interrupt has to be used to load sine table values to CCPRxL register. So, use 1:1 or 1:2 prescalar and make a math routine which finds out the values to be loaded to TMR1H and TMR1L registers. Convert ADC value to Frequency value and based on this frequency value calculate Timer register values and load the proper values in ISR.
 

Hello,betwixt that is what I did with ADC only I get good values but when adding PWM capabilities I get nothing I can`t adjust the duty cycle of my PWM.
 

Please show your interrupt routine for reading the ADC and explain how you know the values it returns are correct.

Brian.
 

Before I used the same ADC settings and generate a PWM which is variable (simply PWM with ADC) but when the same settings are imported in the project I got nothing and the signal I am getting on the oscilloscope in proteus in not clear at all.Find my project here in attachment with proteus circuit for simulation purposes.
 

Attachments

  • Simulation.zip
    94.1 KB · Views: 109

I have made variable frequency code but not sure if the frequencies are correct. Test the attached .hex file in hardware and reply. Scale your 220 or 230 V to 5V DC for ADC input. 5V ADC input represents 35 Hz sine wave. Frequencies are varying but not sure if frequencies are correct. Check in oscilloscope.
 

Attachments

  • 3 Phase SPWM VF.rar
    19.1 KB · Views: 107
  • 3 Phase V-f.png
    3 Phase V-f.png
    100.5 KB · Views: 128
  • 3 Phase V-f-2.png
    3 Phase V-f-2.png
    94.9 KB · Views: 122
  • 3 Sine Wave.png
    3 Sine Wave.png
    89.8 KB · Views: 127

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top