Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Calculation suggestions ?

Status
Not open for further replies.

sandeepa

New Member
Task is to flash light at different rates, based on the setting. Value will be entered with switches.
The range for flash setting is a long one: around 100 to 10000 flashes per minutes.
The time calculation then becomes (60/flash setting)*10^6 for time in us.The timer can be set to exactly this value, or there can be a counter for each setting.Which leads to more calculations.
The flash resolution I need is upto 1 flash/setting. I need accuracy in the calculations. This kind of division will be difficult to do in 16F.
Another option would be to use look up tables. But again, my range is quite large, so cant have that option either.

I have a feeling, I am missing a point somewhere and there would be a simpler way to accomplish it. Any ideas ?

Thanks in advance.
 
Would it be better to go for a 18F series PIC taht can have crystal upto 40MHz and would be easier to program using C than in assembly ?
 
How can you have "10000 flashes per minutes."
Firslty I suggest you get your Engwlish up to scraatch and then ask for som_thing that sensibl-ible.
 
It is simple,

1 - You need to make an oscillator that can simply oscillate 1 Hz to 170 Hz by a resistive incriment / decriment. ( Simple 555 astable Multi Vibrator May enough )

2 - Use your micro controller to controll it, and interface switch with the controller.

3 - Interface different resistance with the microcontroller port that gives the voltage to the oscillator..

4 - you can add many functions with this, and the programming is going to be very simple as you are not going to set the time .

If you need to controll very accurately by Hz by Hz then tell me I will suggest something more more...!
 
Last edited:
It seems a range of 100 to 10000 flashes per minute translates to a frequency of 1.667 to 166.667 Hertz which could easily be generated using a DDS (Direct Digital Synthesis) algorithm and a square wave waveform table.

Search for "pic function generator" which should yield a couple examples using DDS to generate sine, square, or triangle wave forms.

Kind regards, Mike
 
Picture6.jpg


1 Hz to 170 Hz is the range I mentioned, But This DDS is seems to have much costlier system design I feel Mr. Mike, But We have more better options rite ? Cost effective etc.....


As per the Above Blocks , Adjust the resistance and do better system....

Very Cost Effective one Rite ? Accurate , Simple....!


Why That Much Complications, use even 1.1 Hz Incriment ........
 
Last edited:
1 Hz to 170 Hz is the range I mentioned, But This DDS is seems to have much costlier system design I feel Mr. Mike, But We have more better options rite ? Cost effective etc.....


As per the Above Blocks , Adjust the resistance and do better system....

Very Cost Effective one Rite ? Accurate , Simple....!


Why That Much Complications, use even 1.1 Hz Incriment ........

Hi sanalece,

Don't be intimidated by the theory behind Direct Digital Synthesis. Relatively simple DDS code can perform the same function as your external variable frequency oscillator hardware (with considerably more precision).

I put together an example DDS square wave interrupt driver 'engine' below with a 16-bit phase accumulator for you and the OP to look at. I selected a DDS sample interval (PWM period) that allows us to use the "flashes per minute" variable directly as the phase accumulator frequency phase offset so there's practically no math required in the driver. I also omitted the DDS waveform table since we're generating a square wave (the most significant bit of the phase accumulator determines when to toggle the output). The main program simply needs to place a 100..10000 value in the "flashes per minute" variable to get the desired output from the interrupt driven DDS 'engine'.

I leave it to you and the OP to research the DDS theory and math behind this simple driver on your own, if you're interested.

Kind regards, Mike

Code:
;******************************************************************
;  100 to 10000 pulse-per-minute DDS square wave ISR engine       *
;******************************************************************
        org     0x004
;
;  setup PWM for a 920-usec (1086.96-Hz) period using the 8-MHz
;  internal oscillator, timer 2 prescaler = 16, and PR2 = 114.
;
;  [COLOR=Magenta]void interrupt()             // 920-usec/1086.96-Hz interrupts[/COLOR]
;  [COLOR=Magenta]{ pir1.TMR2IF = 0;           // clear timer 2 interrupt flag[/COLOR]
;    [COLOR=Magenta]accu += FlashPerMinute;    // bump phase accumulator[/COLOR]
;    [COLOR=Magenta]ccpr1l = 0;                // duty cycle 0%, output 'lo'[/COLOR]
;    [COLOR=Magenta]if(accu.15)                // if hi portion of square wave[/COLOR]
;      [COLOR=Magenta]ccpr1l = 115;            // duty cycle 100%, output 'hi'[/COLOR]
;  [COLOR=Magenta]}                            //[/COLOR]
;
        radix   dec
v_interrupt
        movwf   w_isr           ; save WREG                       |B?
        swapf   STATUS,W        ; doesn't change STATUS bits      |B?
        movwf   s_isr           ; save STATUS reg                 |B?
        clrf    STATUS          ; bank 0                          |B0
        bcf     PIR1,TMR2IF     ; clear TMR2 interrupt flag       |B0
;
;  add phase offset (100..10000) to phase accumulator
;
        movf    fpm_l,W         ; phase offset lo                 |B0
        addwf   accu_l,F        ; add to phase accumulator lo     |B0
        skpnc                   ; carry? no, skip, else           |B0
        incf    accu_h,F        ; add in carry                    |B0
        movf    fpm_h,W         ; phase offset hi                 |B0
        addwf   accu_h,F        ; add to phase accumulator hi     |B0
;
;  set duty cycle to 0% (lo) or 100% (hi) for next PWM period
;
        movlw   0               ; duty cycle 0%, output 'lo'      |B0
        btfsc   accu_h,7        ; if hi portion of square wave    |B0
        movlw   115             ; duty cycle 100%, output 'hi'    |B0
        movwf   CCPR1L          ; set PWM duty cycle              |B0
;
;  restore context
;
        swapf   s_isr,W         ;                                 |B0
        movwf   STATUS          ; restore STATUS                  |B?
        swapf   w_isr,f         ; don't change STATUS             |B?
        swapf   w_isr,W         ; restore WREG                    |B?
        retfie                  ; return from interrupt           |B?

;******************************************************************
 
Last edited:
Thanks a lot for the reply, Mike,K8LH. Thats a lot of stuff to take in and understand. I was really stuck at this one, thanks a lot for the direction and the smple code.
 
Hi sandeepa,

You're very welcome Sir.

I realize the DDS theory and math may be daunting but you have to admit it reduces down to relatively simple and elegant code.

May I ask what you're doing with this 100-10000 pulse-per-minute application?

Good luck on your project.

Kind regards, Mike
 
Hi sandeepa,

You're very welcome Sir.

I realize the DDS theory and math may be daunting but you have to admit it reduces down to relatively simple and elegant code.

May I ask what you're doing with this 100-10000 pulse-per-minute application?

Good luck on your project.

Kind regards, Mike

--------------------------------------------

Picture6.jpg

Thank you Mr Mike For your Advice. I admire you ...!


But let me Ask you, Do my design will satisfy the need or not ?

She can do much better than she can, is it so...!


I want that only.... Dear Friend......!


https://en.wikipedia.org/wiki/File:Direct_digital_synthesizer_block_diagram.png

I thought it was the DDS....!

But you are saying other type of DDS........!

I didn't know that was... Really thank you
 
Last edited:
The application is a stroboscope with a flash per minute setting made by the user.
Do you suggest any particular link for the understanding of DDS besides what google search gives ?

Thanks.
 
Hi sandeepa,

Thank you for explanation. Sounds like a very interesting project.

I don't remember particular links but I do remember studying several "DDS Function Generator" examples, some with very good explanations, and many other "DDS Theory" links over time.

Good luck on your project.

Kind regards, Mike
 
Last edited:
Hello Mike
I havent yet completely understood the theory behind DDS, but I tried the code you posted with a few modifications, and it seems to work !!
Just to make sure I have actually understood the calculations:
The frequency you set for the PWM is (1/60)*2^16 - interrupt processing time, right ? PWM operates at 50% duty cycle.
And if I need finer tuning, like say an increment of 0.1 flashes per minute, I ll need to change the calculation to (0.1/60)*2^16.

Is this all correct ?

Thanks a lot !!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top