INTERRUPT PROBLEM

Re: INTERRUPT PROBLEM

Postby Manoj » Tue May 22, 2018 10:12 am

AussieSusan wrote:Before spinning off on another problem (clock speed), have you solved the problem with not entering the 'then' clause o the 'if' statement?
Susan



Yes I kept preiod as float .and its working.
but I wanted to achive a frequency of 1280,000Hz, by reaching pr5=12 .I was only able to reach pr5=21 with stepwave . Its not able to toggle Stepwave beyond that.
If I omit Stepwave from code It easily reach upto pr5=12 (i.e. 1280000Hz). These are limitations I think.
Thank you.
Manoj
 
Posts: 21
Joined: Mon Apr 09, 2018 8:01 am

Re: INTERRUPT PROBLEM

Postby AussieSusan » Wed May 23, 2018 2:20 am

A wild guess (as I really still cannot follow your overall logic) but by setting PR5 with such a low value you are making the ISR be called at a very high rate (you mention 1.28MHz) for a system that has an Fcy of 16MHz. By the time you add in the ISR calling and returning overhead, you only have time for a very few instructions before the ISR needs to be called again.
In other words you are doing too much in the ISR for that sort of interrupt frequency.
I really don;t see why you are trying to bit-bang the PWM when there is hardware to do all of the hard work for you.
Susan
AussieSusan
Verified identity
 
Posts: 93
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: INTERRUPT PROBLEM

Postby Manoj » Wed May 23, 2018 4:40 am

Do you mean external hardware or the mcu can produce it by programming it?
If it is possible via programming can you please send me any example code or the code structure.
Manoj
 
Posts: 21
Joined: Mon Apr 09, 2018 8:01 am

Re: INTERRUPT PROBLEM

Postby AussieSusan » Fri May 25, 2018 4:03 am

The MCU you are using has an Output Compare module that can be set up as a PWM. It can also use the system clock as an input so your basic timing is Tosc*2. You cay you use Fcy of 16MHz to the input clock can be up to 8MHz.
There are two register that control everything: one sets how long the pulse is and the other sets when the cycle resets (look at the data sheet for the actual register names). For example, if you set the pulse width register to be '5', and the reset counter to be '10' then you will get a pulse that is 5 clocks wide that repeats every 10 clocks.
You want a square wave so you need to set the pulse with counter to half the reset timer.
You can change the values of these registers while the PWM is running and it will use the new values on the next reset timeout.
When you get to the top end of your frequency range then you might find you can't be as specific as you want to be. Also you may be a bit restricted because of the 50% duty cycle. For example, a 1MHZ output has a reset value of '8' and a pulse width value of '4'. However the next step up is 2MHz (reset counter = 7) but the pulse width cannot be set to 3.5 and so the duty cycle will be either above or under 50%.
On the other hand, at the lower end of the frequency range, you can have very precise control.
How often you want to update the frequency is then up you your code but the hardware is doing all of the work generating the signal for you.
Susan
AussieSusan
Verified identity
 
Posts: 93
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: INTERRUPT PROBLEM

Postby Manoj » Fri May 25, 2018 9:15 am

okay.I will try
Manoj
 
Posts: 21
Joined: Mon Apr 09, 2018 8:01 am

Previous

Return to PIC24

Who is online

Users browsing this forum: No registered users and 23 guests